1.Insertion sort
Insert a data element to the new array every time , keep the new array still in order.
The insertion sort just like this :
Beware:I use php to achieve the sort function from small to large,for convenient I use few php array function , But don't impact the sort algorithm; and we assume the array argement will be sorted are numeric which the key value begin with 0.
2.Selection sort
Get a smallest(or bigest) element from the array , put it to the last of the sort array, until all the element be puted from array to sort array.
e.g:
3.Bubble sort
Compare two element , if the first element is smaller(or bigger ) than second element , reverse two element , until all the element sequence are correct.
e.g:
4.Quick sort
If the array are array[0 to n] , Select a element array[x] to the base comparition , Then put the other element to the left of array[x] which smaller than array[x] , and put the other element to the right of array[x] which bigger than array[x] . Recursive quick sort left array and right array , until array empty.
e.g:
5.Heap sort
Think the array are complete binary tree , sort the array to a heap , the smallest(or biggest) element will appear in the root of binare tree , switch the root element and the last element . Then recursive heap sort the rest of binary tree node except the last element been switched last time.
e.g: