string字母排序,

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication1
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string[] str =  { "student","iphone","abs","ball","wc"};
14             SortStringArray(str,SortType.rise);
15 
16             for (int i = 0; i < str.Length; i++)
17             {
18                 Console.WriteLine(str[i]);
19             }
20 
21             Console.ReadKey();
22         }
23 
24 
25 
26         //按字母排序
27         static void SortStringArray(string [] array,SortType type) 
28         {
29             string temp = null;
30 
31             //降序
32             if (type == SortType.drop)
33             {
34                 for (int i = 0; i < array.Length; i++)
35                 {
36                     for (int j = i; j < array.Length; j++)
37                     {
38                         if ((int)array[i][0] < (int)array[j][0])
39                         {
40                             temp = array[i];
41                             array[i] = array[j];
42                             array[j] = temp;
43                         }
44                     }
45                 }
46             }//升序
47             else if(type == SortType.rise)
48             {
49                 for (int i = 0; i < array.Length; i++)
50                 {
51                     for (int j = i; j < array.Length; j++)
52                     {
53                         if ((int)array[i][0] > (int)array[j][0])
54                         {
55                             temp = array[i];
56                             array[i] = array[j];
57                             array[j] = temp;
58                         }
59                     }
60                 }
61             }
62 
63 
64 
65         }
66 
67         public enum SortType
68         {
69             drop,
70             rise
71         }
72 
73     }
74 
75 }

 

冒泡算法对string数组排序O(∩_∩)O~

新人求关照,求大家多多指点

 

posted @ 2014-12-06 17:01  盘子脸  阅读(771)  评论(0编辑  收藏  举报