Contoh Program Quick Sort
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include #include #include int data[100]; int n; void tukar(int a,int b) { int t; t = data[b]; data[b] = data[a]; data[a] = t; } void QuickSort(int L, int R) { int i, j; int mid; i = L; j = R; mid = data[(L+R)/2]; do { |
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | while (data[j] > mid) j--; if (i <= j) { tukar(i,j); i++; j--; } } while (i < j); if (L < j) QuickSort(L, j); if (i < R) QuickSort(i, R); } void Input() { cout<<"Masukkan jumlah data = "; cin>>n; for(int I = 0; I < n; i++) { cout<<"Masukkan data ke-"<<(i+1)<<" = "; cin >> data[i]; } } void Tampil() { for(int j = 0; j < n; j++) cout << data[j] << setw(3); cout << endl; } void main() { Input(); cout < Tampil(); QuickSort(0,n-1); cout << endl << "Data setelah diurutkan:" << endl; Tampil(); getch(); } |
Penjelasan
2 komentar:
kang tiasa di downloads ?http://i599.photobucket.com/albums/tt76/muba-rock/10pzuz5_th.gif
mangga,.download we...:~
Posting Komentar