Created
October 15, 2017 14:35
-
-
Save myusufid/a9e6e7dd130f0b6d1d086b82bf2a78cb to your computer and use it in GitHub Desktop.
Buble Sort
This file contains 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
///buble sort | |
#include <cstdlib> | |
#include <iostream> | |
using namespace std; | |
int main(int argc, char** argv) { | |
int number[5] = {5,4,2,1,4}; | |
int min = 0; | |
cout<<"Sebelum urut"; | |
for(int i=0;i<5;i++){ | |
cout<<number[i]; | |
} | |
//urut ascending | |
for(int i=1;i<5;i++){ | |
for(int j=4;j>=i;j--){ | |
if(number[j]<number[j-1]){ | |
min = number[j]; | |
number[j]=number[j-1]; | |
number[j-1] = min; | |
} | |
} | |
} | |
for(int i=0; i<5;i++){ | |
cout<<number[i]; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment