选择排序和插入排序c#源码

时间:2012-07-03 19:30:02
【文件属性】:
文件名称:选择排序和插入排序c#源码
文件大小:1KB
文件格式:TXT
更新时间:2012-07-03 19:30:02
选择排序 插入排序 选择排序&插入排序 //选择排序 public void select_sort(int[] a) { int n = a.Length; int minIndex=0; int temp; for (int i = 0; i < n - 1; i++) { minIndex = i; for (int j = i; j < n; j++) { if (a[minIndex] > a[j]) minIndex = j; } if (minIndex != i) { temp = a[i]; a[i] = a[minIndex]; a[minIndex] = temp; } } } //插入排序 public void insert_sort(int[] a) { int n = a.Length; int temp; int j; for (int i = 1; i < n; i++) { temp=a[i]; for (j = i - 1; j >= 0 && temp < a[j]; j--) { //if (temp < a[j]) // { a[j + 1] = a[j]; // } //else //{ // // a[j + 1] = temp; // break; //} } // if (j < 0) // { a[j + 1] = temp; // } } }

网友评论