#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]<<" ";
}

 

相关文章:

  • 2021-10-11
  • 2021-12-28
  • 2021-10-23
  • 2021-06-27
  • 2021-11-08
猜你喜欢
  • 2021-08-08
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2022-02-23
  • 2021-07-19
  • 2021-08-28
相关资源
相似解决方案