鸡尾酒排序

 1  public int[] Ripple(int[] sortData)
 2         {
 3             int StartIndex = 1;
 4             int top = sortData.Length - 1;
 5             int Bottom = 0;
 6             int step = 1;
 7             int swap;
 8             while (Bottom < top)
 9             {
10                 for (int i = StartIndex; Bottom <= i && i <= top; i = i + step)
11                 {
12                     if (step == 1)
13                     {
14                         if (sortData[i] < sortData[i - 1])
15                         {
16                             swap = sortData[i];
17                             sortData[i] = sortData[i - 1];
18                             sortData[i - 1] = swap;
19                         }
20                     }
21                     else
22                     {
23                         if (sortData[i + 1] < sortData[i])
24                         {
25                             swap = sortData[i];
26                             sortData[i] = sortData[i + 1];
27                             sortData[i + 1] = swap;
28                         }
29                     }
30                 }
31                 if (step == -1)
32                 {                  
33                     Bottom++;
34                     StartIndex = Bottom + 1;
35                 }
36                 else
37                 {                    
38                     top--;
39                     StartIndex = top - 1;
40                 }
41                 step = step * -1;
42             }
43             
44             return sortData;  
45         }

转载于:https://www.cnblogs.com/bingxueme/archive/2012/05/16/2503503.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值