Breaking News
Loading...
Minggu, 17 April 2016

Ebook 4.5

Source Code :



#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];
                cout<<endl;
                quicksort(data,0,7);
                cout<<"terurut : "<<data[8];
                return 0;
}


Hasilnya :

0 komentar:

Posting Komentar

Copyright © 2014 My Blog My Adventure All Right Reserved