#include <iostream.h> #include <conio.h> void main(void){ int dataku[] = {4,5,2,8,1,3,4}; int adaPertukaran; int calo; //pengurutan do { adaPertukaran = 0; for (int i = 0; i < 7-1; i++){ if (dataku[i+1] < dataku[i]){ calo = dataku[i]; dataku[i] = dataku[i+1]; dataku[i+1] = calo; adaPertukaran = 1; } } } while (adaPertukaran == 1); //menampilkan hasil pengurutan for (int i = 0; i < 7; i++){ cout << dataku[i] << endl; } getch(); }
Jumat, 03 Agustus 2012
Source Code C++ : Bubble Sort
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar