Skip to content

Instantly share code, notes, and snippets.

@myusufid
Created October 15, 2017 14:35
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 myusufid/a9e6e7dd130f0b6d1d086b82bf2a78cb to your computer and use it in GitHub Desktop.
Save myusufid/a9e6e7dd130f0b6d1d086b82bf2a78cb to your computer and use it in GitHub Desktop.
Buble Sort
///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