-
피봇을 맨 왼쪽으로 잡는 퀵 정렬(LR)
#include <stdio.h>
#define SIZE 10
int printo(int arri[])
{
int i;
for(i=0;i<SIZE;i++)
{
printf("%d ",arri[i]);
}
printf("\n");
return 0;
}
int swap(int *i, int *j)
{
int imsi;
imsi=*i;
*i=*j;
*j=imsi;
}
int qsorting(int arr[],int low, int high)
{
int pivot=arr[low];
int i=low, j=high;
while(i<=j)
{
while(arr[i]<pivot)
i++;
while(arr[j]>pivot)
j--;
if(i<=j)
{
swap(&arr[i],&arr[j]);
i++;
j--;
//printo(arr);
}
}
if(low<j)
qsorting(arr,low,j);
if(high>i)
qsorting(arr,i,high);
}
int main()
{
int arr[SIZE]={9,81,25,7,6,1,2,35,0,50};
printo(arr);
qsorting(arr,0,SIZE-1);
printo(arr);
return 0;
}