5 1 2 4 8 7
(기준값보다작은값들) 5 (기준값보다 큰 값들)
quick_sort
qs(int s, int e) // a[s] ~ a[e] 정렬
___________________________________
while (@#%^&*)
{
%^&*%
}
|
| /
do(@#$%^)
{
@#%$@%
}
____________________________
#include <stdio.h>
int a[50001],s[50001];
int bs(int s,int e,int n)
{
if(s>e)
{
return - 2;
}
int mid=(s+e)/2;
if(a[mid]==n)
{
return mid;
}
else if(a[mid]>n)
{
bs(s,mid-1,n);
}
else
{
bs(mid+1,e,n);
}
}
int main()
{
int n,i,j,sum,u[50001];
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
u[i]=a[i];
}
for(i=1; i<n; i++)
{
for(j=1; j<=n-i; j++)
{
if(a[j]>a[j+1])
{
sum=a[j];
a[j]=a[j+1];
a[j+1]=sum;
}
}
}
_______________________________________________________
#include <stdio.h>
int a[100001];
void qs(int s, int e)
{
int pivot = s; //기준값의 위치
int low=s,high=e;
int temp;
if(s>=e) return;
while(low<high)
{
while(a[pivot]>a[low]){
low++;
}
while(a[pivot] < a[high]){
high--;
}
if(low<high)
{
temp=a[high];
a[high]=a[low];
a[low]=temp;
}
}
//a[pivot]보다 작은수 .... a[pivot] .... a[pivot]보다 큰수
qs(s,high-1);
qs(high+1,e);
}
int main()
{
int i,n,v;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
qs(1,n);
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
}
____________________________________________________________
#include <stdio.h>
int a[100001];
void qs(int s, int e)
{
int pivot = s; //기준값의 위치
int low=s,high=e+1;
int temp;
if(s>=e)
return;
do
{
do
{
low++;
}
while(a[pivot]>a[low]);
do
{
high--;
}
while(a[pivot] < a[high]);
if(low<high)
{
temp=a[high];
a[high]=a[low];
a[low]=temp;
}
}
while(low<high);
temp=a[pivot];
a[pivot]=a[high];
a[high]=temp;
//a[pivot]보다 작은수 .... a[pivot] .... a[pivot]보다 큰수
qs(s,high-1);
qs(high+1,e);
}
int main()
{
int i,n,v;
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
qs(1,n);
for(i=1; i<=n; i++)
{
printf("%d\n",a[i]);
}
}
____________________________________________________________________________________