Skip to content

Instantly share code, notes, and snippets.

@rmsubekti
Created October 11, 2016 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmsubekti/604bc3c1914195c356372cec6bc3fbd8 to your computer and use it in GitHub Desktop.
Save rmsubekti/604bc3c1914195c356372cec6bc3fbd8 to your computer and use it in GitHub Desktop.
# include <iostream>
int main(int argc, char const *argv[]) {
int arr[6]={5,2,10,50,70,60},
swap,
jumlah = sizeof(arr)/sizeof(arr[0]);
std::cout << "Data yang akan diurutkan : " << std::endl;
for (int i = 0; i < jumlah; i++) {
std::cout << "arr["<< i <<"] = "<< arr[i] << std::endl;
}
//Bubble Short Ascending
for (int i = 0; i < jumlah; i++) {
for (int j = 0; j < jumlah; j++) {
if (arr[j] > arr[j +1]) {
swap = arr[j];
arr[j]=arr[j+1];
arr[j+1] = swap;
}
}
}
// menampilkan Bubble short Ascending
std::cout << "\nSetelah diurutkan secara Ascending : " << std::endl;
for (int i = 0; i < jumlah; i++) {
std::cout << "arr["<< i <<"] = "<< arr[i] << std::endl;
}
//Bubble Short Descending
for (int i = 0; i < jumlah; i++) {
for (int j = 0; j < jumlah; j++) {
if (arr[j] < arr[j +1]) {
swap = arr[j];
arr[j]=arr[j+1];
arr[j+1] = swap;
}
}
}
// menampilkan Bubble short Descending
std::cout << "\nSetelah diurutkan secara Descending : " << std::endl;
for (int i = 0; i < jumlah; i++) {
std::cout << "arr["<< i <<"] = "<< arr[i] << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment