首页 > 编程语言 > 详细

c#复习-冒泡排序

时间:2016-06-16 23:04:22      阅读:270      评论:0      收藏:0      [点我收藏+]
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace 冒泡排序
 7 {
 8 
 9 在其他类中定义一组变量
10     class Student
11     {
12         public string Code;
13         public string Name;
14         public decimal Score;
15     }
16 }
 1 using System;
 2 using System.Collections;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 
 7 namespace 冒泡排序
 8 {
 9     class Program
10     {
11 
12         static void Main(string[] args)
13         {
14             ArrayList arr = new ArrayList();
15 
16             Student s = new Student(); //实例化
17 
18             s.Code = "101";
19 
20             Student s1 = new Student();
21             s1.Code = "102";
22 
23 
24             arr.Add(5);
25             arr.Add(6);
26             arr.Add(8);
27             arr.Add(1);
28             arr.Add(3);
29 
30             foreach (object o in arr)
31             {
32                 Console.WriteLine(o);
33             }
34 
35             Console.WriteLine("---------------------------------");
36 
37             for (int i = 0; i < arr.Count; i++)
38             {
39                 for (int j = i + 1; j < arr.Count; j++)
40                 {
41                     if (Convert.ToInt32(arr[i]) < Convert.ToInt32(arr[j]))
42                     {
43                         int zhong = 0;
44 
45                         zhong = Convert.ToInt32(arr[i]);
46                         arr[i] = arr[j];
47                         arr[j] = zhong;
48                     }
49                 }
50             }
51 
52             foreach (object o in arr)
53             {
54                 Console.WriteLine(o);
55             }
56 
57 
58             Console.ReadLine();
59         }
60     }
61 }

技术分享

c#复习-冒泡排序

原文:http://www.cnblogs.com/tonyhere/p/5592227.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!