编写一个类,其中包含一个排序的方法Sort(),当传入的是一串整数,就按照从小到大的顺序输出,如果传入的是一个字符串,就将字符串反序输出。...

 1 namespace test2
 2 {
 3     class Program
 4     {
 5         /// <summary>
 6         /// 编写一个类,其中包含一个排序的方法Sort(),当传入的是一串整数,就按照从小到大的顺序输出,如果传入的是一个字符串,就将字符串反序输出。
 7         /// </summary>
 8         /// <param name="args"></param>
 9         static void Main(string[] args)
10         {
11             int[] a = { 6, 2, 3, 4, 5 };//注意定义格式和c语言不同
12             Change b = new Change(a);
13             Console.ReadKey();
14         }
15     }
16     class Change
17     {
18         int k, t;
19         void Sort(int[] a)
20         {
21             for (int i = 0; i < a.Length; i++)
22             {
23                 int k = i;
24                 for (int j = i + 1; j < a.Length; j++)
25                 {
26                     if (a[k] > a[j])
27                         k = j;
28 
29                 }
30                 t = a[i]; a[i] = a[k]; a[k] = t;  //注意超限
31             }
32         }
33         public Change(string strs)
34         {
35             int len = strs.Length;
36             for (int i = strs.Length-1; i >= 0; i--)
37             {
38                 Console.Write("{0} ", strs[i]);
39 
40             }
41 
42         }
43         public Change(int[] a)
44         {
45             Sort(a);
46             for (int i = 0; i < a.Length; i++)
47             {
48                 Console.Write("{0} ",a[i]);
49             }
50         }
51     }
52 }

 

转载于:https://www.cnblogs.com/zj-kingder/p/6281904.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值