퀵정렬 temp

      

          #define MAX 12
  
          typedef struct node {  
             int l, r;  
          } NODE;  

          void sort1(int a[], int l, int r) {  
             NODE stack[MAX];  
             int i, j, x, temp, top = -1;  

             stack[top].l = l;
             stack[top].r = r;  

             do {  
                l = stack[top].l;
                r = stack[top--].r;  
                do {  
                   i = l; j = r; x = a[(l+r)/2];  
                   do {  
                      while (a[i]<x) i++;  
                      while (a[j]>x) j--;  
                      if (i<=j) {  
                         temp = a[i]; a[i] = a[j]; a[j] = temp;  
                         i++; j--;  
                      }  
                   } while (i<=j);  
                   if (i<r) {  
                      stack[++top].l = i; stack[top].r = r;  
                   }  
                   r = j;  
                } while (l < r);  
             } while (top != -1);  
          } 

[출처] 퀵정렬|작성자 제리

이 글을 공유하기

댓글

Designed by JB FACTORY