#include<stdio.h>
#define max 20
void quick_sort(int M[max], int k, int l)
{
int a;
int p,q;
int temp;
if (k>=l)
return;
a=M[k];
p=l;
q=k;
while (q < p)
{
while (M[q] <= a)
q++;
while (M[p]>a)
p--;
if(q<p)
{
temp=M[q];
M[q]=M[p];
M[p]=temp;
}
}
M[k]=M[p];
M[p]=a;
quick_sort(M,k,p-1);
quick_sort(M,p+1,l);
}
int main()
{
int L[max];
int i,n,k,l;
k=0;
printf("Masukkan banyak data: ");
scanf("%i",&n);
l=n;
printf("Masukkan data-datanya: \n");
for(i=0;i<n;i++)
{
printf("data ke-%i: ",i);
scanf("%i",&L[i]);
}
quick_sort(L,k,l);
printf("\nHasil pengurutan data: ");
for(i=1; i<=n;i++)
printf("%i ",L[i]);
}
Algoritma Quick Sort Pada C++
Labels:
Disain Analisis Algoritma,
Semester 3
0 comments:
Post a Comment