Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #define N 20
- using namespace std;
- int bubble(int n);
- int i,j,A[N];
- int main()
- {
- int jml;
- cout<<"\t METODE BUBBLE SORT \n\n";
- cout<<"Masukkan jumlah bilangan: ";
- cin>>jml;
- cout<<endl;
- // input data
- for (i=0;i<jml;i++){
- cout<<"Bilangan ke "<<i+1 <<" : ";
- cin>>A[i];
- }
- cout<<endl;
- // mengurutkan data
- bubble(jml);
- // menampilkan data
- cout<<"Data yang sudah terurut : \n";
- for (i=0;i<jml;i++){
- cout<<A[i]<<endl;
- }
- }
- // fungsi bubble
- int bubble(int n){
- int temp;
- for (i=1;i<=n-1;i++){
- for (j=i;j<n;j++){
- if (A[i-1]>A[j]){
- temp = A[i-1];
- A[i-1] = A[j];
- A[j] = temp;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment