标签:list public void length code color 算法 i++ span
1.冒泡排序
1 public void sortM(int[] list) 2 { 3 int i, j, temp; 4 bool done = false; 5 j = 1; 6 while ((j < list.Length) && (!done)) 7 { 8 done = true; 9 for (i = 0; i < list.Length - j; i++) 10 { 11 if (list[i] > list[i + 1]) 12 { 13 done = false; 14 temp = list[i]; 15 list[i] = list[i + 1]; 16 list[i + 1] = temp; 17 } 18 } 19 j++; 20 } 21 }
2.选择排序
1 public void sortS(int[] list) 2 { 3 int min; 4 for (int i = 0; i < list.Length - 1; i++) 5 { 6 min = i; 7 for (int j = i + 1; j < list.Length; j++) 8 { 9 if (list[j] < list[min]) 10 min = j; 11 } 12 int t = list[min]; 13 list[min] = list[i]; 14 list[i] = t; 15 } 16 }
3.插入排序
1 public void sortI(int[] list) 2 { 3 for (int i = 1; i < list.Length; i++) 4 { 5 int t = list[i]; 6 int j = i; 7 while ((j > 0) && (list[j - 1] > t)) 8 { 9 list[j] = list[j - 1]; 10 --j; 11 } 12 list[j] = t; 13 } 14 }
标签:list public void length code color 算法 i++ span
原文地址:http://www.cnblogs.com/ch2017/p/6881575.html