鸡尾酒排序
1 void changes(ref int a1, ref int a2)
2 {
3 int tep = a1;
4 a1 = a2;
5 a2 = tep;
6 }
7
8 void getSelectInts(ref int[] myints)
9 {
10 int smallest;
11 for (int i = 0; i < myints.Length-1; i++)
12 {
13 smallest = myints[i];
写算法,不只是需要看算法,而且是需要纸笔,还有一台电脑………………
选择排序
Code
选择排序是相当的直观,简单,挑出最值,放到开始元素……不停的放就ok了
1 void changes(ref int a1, ref int a2)
2 {
3 int tep = a1;
4 a1 = a2;
5 a2 = tep;
6 }
7
8 void getSelectInts(ref int[] myints)
9 {
10 int smallest;
11 for (int i = 0; i < myints.Length-1; i++)
12 {
13 smallest = myints[i];
14 for (int j = i + 1; j < myints.Length; j++)
15 {
16 if (myints[j] < smallest)
17 {
18 changes(ref myints[j],ref smallest);
19 }
20 }
21 myints[i] = smallest;
22 }
23
15 {
16 if (myints[j] < smallest)
17 {
18 changes(ref myints[j],ref smallest);
19 }
20 }
21 myints[i] = smallest;
22 }
23