Hai aku pengen share lagi nih alpro kodingan c++
langsung aja ya..
ini adalah program QUICK SORT
#include <iostream>
#include <conio.h>
using namespace std;
int quicksort( int arr[100], int kiri, int kanan)
{
int i=kiri, j=kanan;
int tmp;
int pivot=arr[(kiri+kanan)/2];
while(i<=j)//syarat
{
while(arr[i]<pivot)
i++;
while(arr[j]>pivot)
j--;
if(i<=j)
{
tmp=arr[i];
arr[i]=arr[j];
arr[j]=tmp;
i++;
j--;
}
}
if(kiri<j)
quicksort(arr,kiri,j);
if(i<kanan)
quicksort(arr,i,kanan);
}
int main()
{
int arr[100];
int i,n,a,b;
a=1;
cout<<" PROGRAM QUICK SORT \n";
cout<<"_________________________________\n";
cout<<"masukkan banyak data yang di urut: ";
cin>>n;
b=n;
cout<<"masukkan data : \n\n";
for(i=1; i<=n; i++)
{
cout<<"\tdata ke- "<<i<<" : ";
cin>>arr[i];
}
quicksort(arr,a,b);
cout<<"\nHasil pengurutan data: ";
for(i=1; i<=n; i++)
cout<<" "<<arr[i];
getch();
}