KOREA University/C++2008. 10. 3. 02:40
#include <iostream>
#include <cstring>
using namespace std;
void QuickSort(char *element, int len);
void Run(char *element, int left, int right);
int main()
{
 char str[100];
 
 cout << "Insert 문자열 : ";
 cin >> str;
 cout << "퀵정렬 前 : " << str << "\n";
 
 QuickSort(str, strlen(str));
 cout << "퀵정렬 後 : " << str << "\n";
 return 0;
}
void QuickSort(char *element, int len) // 퀵정렬 소환
{
 Run(element, 0, len-1);
}
void Run(char *element, int left, int right) // 실제 퀵정렬의 원리
{
 int i, j;
 char x, y;
 i = left;
 j = right;
 x = element[(left+right)/2];
 while(i<=j)
 {
  while((element[i] < x) && (i < right)) i++;
  while((x < element[j]) && (j > left)) j--;
  if(i<=j)
  {
   y = element[i];
   element[i] = element[j];
   element[j] = y;
   i++; j--;
  }
 }
 if(left < j) Run(element, left, j);
 if(i < right) Run(element, i, right);
}

옛날에 자료구조 수업들을때 교수님이 그랬다.
퀵정렬이 현존 가장빠른 정렬방법이고,
아마 여러분들 중에 퀵정렬보다 더 빠른 정렬을 만든다면 아마도 노벨상 받을꺼라고...

무슨수로 만드냐 ㅡ,.ㅡ;;;
어쨋든 그 유명한 퀵정렬이다.

왼쪽과 오른쪽 경계가 만날 때까지 순서가 어긋난 element들을
서로 교환하면서 왼쪽과 오른쪽 부분을 탐색한다.
Posted by 정훈승