Originally Posted by
teisen
as I was wondering if they might be trying to implement some other functions or have some particular use as well which i wasn't aware of.
Sorting arrays is "very well explored territory"; it is probably impossible, at this point in time, that someone is going to come forward with some kind of new and revolutionary sorting method. It's all done and finished; all you have to do is learn the established methods.
Which means most of the material you will find should reflect this available "state of the art". All you have to do is learn the basic form of the algorithms. It might be a good idea to look at *both* pseudo code descriptions *and* actual C implementations. So pseudo-code for a modified bubblesort might be:
Code:
while (1) { // eg, an infinite loop
set flag to 0
for (i=0; i<the lenght of the array; i++) {
compare i to i+i;
if i+1 is less than i, swap the values and add 1 to flag
}
if the flag is still 0, break out of the loop because the array is sorted.
}
The key here is to set the flag to 0 at the beginning of the while loop, before you iterate thru the array again.
IMO bubblesort is the easiest and most "intuitive" -- that's what I did off the top of my head without knowing anything about sorting, and somebody told me it was a bubblesort. Other people have said the same thing about "selection sort". Insertion sort is pretty straight forward too.
Merge sort is quite a bit trickier. And don't bother with "quick sort" until you understand merge sort.