排序算法
1 int partition(int low, int high) 2 { 3 int pivot = a[low]; 4 while (low < high) 5 { 6 while (low < high && a[high] >= pivot) 7 high--; 8 a[low] = a[high]; 9 while (low < high && a[low] <= pivot) 10 low++; 11 a[high] = a[low]; 12 } 13 a[low] = pivot; 14 return low; 15 16 } 17 18 void quicksort(int low, int high) 19 { 20 if (low < high) 21 { 22 int mid = partition(low, high); 23 quicksort(low, mid - 1); 24 quicksort(mid + 1, high); 25 }
1 int deleteSame(int n, int *p) 2 { 3 int i = 0, same_cun = 0; 4 for (; i < n; i++) 5 { 6 int j = i + 1; 7 while (j < n) 8 { 9 if (p[i] == p[j]) 10 { 11 int temp = j; 12 while (temp < n - 1) 13 { 14 p[temp] = p[temp + 1]; 15 temp++; 16 } 17 n--; 18 } 19 else 20 j++; 21 } 22 } 23 return n; 24 }
26 }