Five kinds of sort algorithm

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:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值