Created
October 11, 2016 06:11
-
-
Save rmsubekti/604bc3c1914195c356372cec6bc3fbd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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