标签:
#include <iostream> using namespace std; int Partion(int arr[],int low,int high) { int index_low=low; int index_high=high; while(index_low<index_high) { while(index_low<index_high&&arr[index_low]<arr[index_high]) { index_high--; } if(arr[index_low]>arr[index_high]) { swap(arr[index_low],arr[index_high]); index_low++; } while(index_low<index_high&&arr[index_low]<arr[index_high]) { index_low++; } if(arr[index_low]>arr[index_high]) { swap(arr[index_low],arr[index_high]); index_high--; } } return index_high; } void QSort(int arr[],int low,int high) { int mid=Partion(arr,low,high); if(low<mid-1) { QSort(arr,low,mid-1); } if(mid+1<high) { QSort(arr,mid+1,high); } } int main() { int arr[]={32,434,54,432,435,333,555,666,76,312,53}; //Partion(arr,0,3); QSort(arr,0,10); for(int i=0;i<=10;i++) { cout<<arr[i]<<" "; } //cout << "Hello world!" << endl; return 0; }
标签:
原文地址:http://www.cnblogs.com/GW17195/p/5726608.html