Minggu, 17 April 2016

how to solve 4.5

c++ :
#include <iostream>
using namespace std;

void quicksort(int *arr, int kiri, int kanan){
int tmp,i=kiri,j=kanan,cetak;
int pivot=arr[(kiri+kanan)/2];

while(i<=j){
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 data[8]={17,10,13,15,18,12,14,16};
cout<<"awal : "<<data[8];
quicksort(data,0,7);
cout<<"terurut : "<<data[8];
return 0;
}

0 komentar:

Posting Komentar