冒泡排序

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace ConsoleApplication1
 7 {
 8     class Program
 9     {
10         static void Main(string[] args)
11         {
12             int[] arrs = { 1, 3, 5, 4, 2, 3, 5, 3, 5, 6, 8, 9, 2, 10 };
13             Srot(arrs);
14             foreach (int item in arrs)
15             {
16                 Console.WriteLine(item);
17             }
18 
19 
20 
21             Console.ReadKey();
22         }
23 
24         public static Array Srot(int[] arr)
25         {
26             int temp;
27             for (int i = 0; i < arr.Length - 1; i++)
28             {
29                 for (int j = 0; j < arr.Length - 1 - i; j++)
30                 {
31                     if (arr[j] > arr[j + 1])
32                     {
33                         temp = arr[j];
34                         arr[j] = arr[j + 1];
35                         arr[j + 1] = temp;
36                     }
37                 }
38             }
39 
40             return arr;
41 
42         }
43     }
44 }
View Code


上课一觉醒来,没事干,写了个函数!

posted on 2013-12-17 10:08  知鸟  阅读(165)  评论(0)    收藏  举报