/*  Bismillahir Rahmanir Rahim
    Implementation of Bubble-Sort using C++
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[50],n,i,j,temp;
    cin>>n; // Enter the number of element
    for(i=0; i<n; i++) cin>>a[i]; // Enter all elements
    for(i=1; i<n; i++){
        for(j=0; j<(n-i); j++){
            if(a[j]>a[j+1]){
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    for(i=0; i<n; i++) cout<<a[i]<<" ";
    cout<<endl;
    return 0;
}
 | 
Monday, April 24, 2017
Bubble Sort - Implementation with C++
Subscribe to:
Post Comments (Atom)
- 
#include<bits/stdc++.h> #define ll long long using namespace std ; ll n , k , t_case ; ll bigmod ( ll b , ll p , ll m...
 - 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...
 - 
View the problem UVa 10685 #include<bits/stdc++.h> using namespace std ; int ar [ 5005 ]; int par ( int z ){ if ( ar...
 
No comments:
Post a Comment