递归实现冒泡排序

ContractedBlock.gifExpandedBlockStart.gifCode
 1None.gifusing System;
 2None.gifusing System.Collections.Generic;
 3None.gifusing System.Text;
 4None.gifusing System.Threading;
 5None.gif
 6None.gifnamespace ConsoleApplication1
 7ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 8InBlock.gif    class maopaodiguipaixu
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
10InBlock.gif
11InBlock.gif        public static void sortay(int[] sz, int i)
12ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
13InBlock.gif            if (i == sz.Length) return;
14InBlock.gif
15InBlock.gif            int midint;
16InBlock.gif            for (int j = sz.Length - 1; j > i; j--)
17ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
18InBlock.gif                
19InBlock.gif                if (sz[j] > sz[j - 1]) //小于号为从小到大,反之为从大到小
20ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
21InBlock.gif
22InBlock.gif                    midint = sz[j];
23InBlock.gif                    sz[j] = sz[j - 1];
24InBlock.gif                    sz[j - 1= midint;
25ExpandedSubBlockEnd.gif                }

26ExpandedSubBlockEnd.gif            }

27InBlock.gif
28InBlock.gif
29InBlock.gif            sortay(sz, i + 1);
30ExpandedSubBlockEnd.gif        }

31InBlock.gif
32InBlock.gif
33InBlock.gif
34InBlock.gif
35InBlock.gif        static void Main()
36ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
37ExpandedSubBlockStart.gifContractedSubBlock.gif            int[] ay =dot.gif339191407 };
38InBlock.gif                      
39InBlock.gif            sortay(ay, 0);
40InBlock.gif
41InBlock.gif            Console.Write("排序结果为:");
42InBlock.gif            foreach(int a in ay)
43InBlock.gif
44InBlock.gif                Console.Write("{0}  ", a);
45InBlock.gif
46InBlock.gif            Thread.Sleep(9000);
47InBlock.gif
48ExpandedSubBlockEnd.gif        }

49ExpandedSubBlockEnd.gif    }

50ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/7goal/archive/2008/08/21/1273218.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值