标签:[] i++ color main ret bsp pac 排序 bre
#include<iostream> #include<cstdio> using namespace std; void swap(int arr[], int i, int j){ int t=arr[i]; arr[i]=arr[j]; arr[j]=t; } int partition(int arr[], int low, int end){ int i=low; int j=end+1; int x=arr[low]; while (1){ while (i<end&&arr[++i]<x); while (arr[--j]>x); if (i>=j) break; swap(arr, i, j); } swap(arr, low, j); return j; } void quicksort(int arr[],int low,int high){ if (low<high){ int p=partition(arr, low, high); quicksort(arr, low, p-1); quicksort(arr,p+1, high); } } int main(){ int arr[6] = {23,1,21, 21,4,19}; quicksort(arr,0,5); for(int i=0;i<6;i++){ printf("%d ",arr[i]); } printf("\n"); }
标签:[] i++ color main ret bsp pac 排序 bre
原文地址:http://www.cnblogs.com/a863886199/p/6916806.html