快速排序

原数列:28,5,36,3,60,13,55,17,总共8个数据,data[0]到data[7]

get l=data[0]    point to the 28,so  i=0

get r=data[7]=data[n-1]=17 so point to the data[8] so j=17

then start to be  compare the number.

the first one,i=2,data[2]=36 ,j=7,data[7]=17 j=7,i<j,so change the number.

28,5,17,3,60,13,55,36 the l=28 point to the 17,and the r=17,point to the 36.

then the i=4, j=5 i<j,changed the number 

28,5,17,3,13,60,55,36  the l=28 point to the 60  ther=17 ,point to the 13.

then the i=5,j=4,i>j, change the number data[0] and the data[4]

13,5,17,28,60,55,36,and the the queue cut to two parts,

13,5,17,28      60,55,36

then the same method!

Tags: 排序

« 上一篇 | 下一篇 »

信息推荐

发表评论