双向冒泡

来源:互联网 发布:js产生一个随机数 编辑:程序博客网 时间:2024/05/01 11:02

按<归则排序

每次循环抽取剩余数组中未排列的数据,取得最大和最小值。

将最小值放剩余数组最前,将最大值放剩余数组最后。

运行结果:

 

plz enter values to sort.press ctrl+break to end input!
values: 11 7 88 4 56 43 110 0 54 22 11 77 8 92 64 32 41^/
The values you enter are :
11      7       88      4       56      43      110     0       54      22
11      77      8       92      64      32      41
Total count = 17
begin:0,end:16
Max:110,Min:0,MaxPos6,MinPos7
begin:1,end:15
Max:92,Min:4,MaxPos13,MinPos3
begin:2,end:14
Max:88,Min:7,MaxPos2,MinPos3
begin:3,end:13
Max:77,Min:8,MaxPos11,MinPos12
begin:4,end:12
Max:64,Min:11,MaxPos12,MinPos7
begin:5,end:11
Max:56,Min:11,MaxPos7,MinPos10
begin:6,end:10
Max:54,Min:22,MaxPos8,MinPos9
begin:7,end:9
Max:43,Min:32,MaxPos8,MinPos7
begin:8,end:8
after sort:
0       4       7       8       11      11      22      32      41      43
54      56      64      77      88      92      110
请按任意键继续. . .

原创粉丝点击