[Sort] 빠른 정렬 - 반복 구현
2491 단어 빠른 정렬
#include<iostream>
using namespace std;
void QuickSort(int a[],int low,int high)
{
if(low < high)
{
int pivot = a[low]; //
int first = low;
int last = high;
while(first < last)
{
while(first < last && a[last] > pivot)
{
--last;
}
a[first] = a[last]; //
while(first < last && a[first] <= pivot)
{
++first;
}
a[last] = a[first]; //
}
a[first] = pivot;
QuickSort(a,low,first-1);
QuickSort(a,first+1,high);
}
else
{
return;
}
}
void main()
{
int a[] = {57,68,59,52,72,28,96,33,24};
int count = sizeof(a) / sizeof(a[0]);
QuickSort(a,0,count-1);
for(int i=0;i<count;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JAVA 버전 정렬 알고리즘의 빠른 정렬 예본고는 JAVA의 빠른 정렬 실현 방법을 실례로 다루고 있다.다음과 같이 여러분에게 참고할 수 있도록 공유합니다. 본고에서 기술한 것이 여러분의 자바 프로그램 설계에 도움이 되기를 바랍니다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.