Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

bubble sort in c+

#include <iostream>
#include <iomanip>

using namespace std;

void sort (int array[],int size){
    for(int i=0; i<size-1; i++){           
      for(int j=i+1; j<size; j++){      
        if(array[i] > array[j]){      
            int temp = array[j];
            array[j] = array[i];
            array[i] = temp;
        }
      }
    }
    cout<<"Sorted Array: 
";
    for(int i=0;i<5;i++){
        cout<<setw(5)<<array[i];
    }
}

int main()
{
    int array [5];
    for(int i=0;i<5;i++){
        cout<<"Element "<<i<<": ";
        cin>>array[i];
    }
    sort(array,5);
  
}
Source by codescracker.com #
 
PREVIOUS NEXT
Tagged: #bubble #sort
ADD COMMENT
Topic
Name
4+8 =