#include
using namespace std;
void tampilkan_larik(int data[], int n){
int i;
for (i = 0; i < n; i++) cout << data[i] << " "; cout << "\n"; } void bubble_sort(int data[], int n){ int tahap, j, temp; int ada_penukaran; tahap = 1; ada_penukaran = 1; while (tahap < n-1 && ada_penukaran){ ada_penukaran = 0; for (j = 0; j
ada_penukaran = 1;
temp = data[j];
data[j] = data[j+1];
data[j+1]=temp;
}
cout << "Tahap" << tahap << ":";
tampilkan_larik(data, n);
tahap++;
}
}
int main()
{
char JUM_DATA = 6;
int i;
int data[] = {6,3,10,2,9,7};
bubble_sort(data, JUM_DATA);
cout<<"Tampilan Hasil pengurutan:\n";
tampilkan_larik(data, JUM_DATA);
system("PAUSE");
return EXIT_SUCCESS;
}
Tidak ada komentar:
Posting Komentar