标签:style c class blog code java
#include<iostream> using namespace std; ////写出快速排序,归并排序与堆排序 int adjustarray(int a[],int left,int right) { int x = a[left]; while(left < right) { while(a[right] > x && left < right) right--; ///注意这个小于的范围 if(left < right ) {a[left] = a[right];left++;} while(a[left] <= x && left < right) left++; if(left < right ) {a[right] = a[left];right--;} } a[left] = x; return left; } void quicksort(int a[],int left,int right) { if(left < right) { int mid = adjustarray(a,left,right); quicksort(a,left,mid - 1); quicksort(a,mid + 1,right); } } int main() { int a[] = {1,5,4,3,2,6,7,4,1,6,7}; quicksort(a,0,10); for(int i = 0;i< 10;i++) cout<<a[i]<<" "; }
标签:style c class blog code java
原文地址:http://www.cnblogs.com/berkeleysong/p/3754558.html