and for the third question, you could try a bubble sort;
Code:
#include <iostream>
using std::cout;
using std::endl;
int main(void){
int array[4] = {3,9,1,5}, x;
int size = sizeof(array)/sizeof(int);
cout << "Unsorted\n";
for(x = 0;x < size;x++)cout << array[x] << '\t';
cout << endl;
for(int pass = 0;pass < size-1;pass++){ //pass through each array member
for(int sorter = 0;sorter < size-1; sorter++){
if(array[sorter] > array[sorter+1]){ //test if bigger than next
int hold = array[sorter+1];
array[sorter+1] = array[sorter];
array[sorter] = hold; // if so, swap them
}
}
}
cout << "Sorted\n";
for(x = 0;x < size;x++)cout << array[x] << '\t';
return 0;
}
That's about the simplest sorting algo out there