Skip to content

Instantly share code, notes, and snippets.

@shemul
Created October 20, 2014 17:22
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 shemul/bbda8c7ee569ea838dac to your computer and use it in GitHub Desktop.
Save shemul/bbda8c7ee569ea838dac to your computer and use it in GitHub Desktop.
bouble sort
#include <iostream>
using namespace std;
int main()
{
int pass= 0 , swap = 0 ;
bool noSwap = false ;
int roll[20];
int element = 3;
cout <<"Enter 3 Roll numbers" <<endl;
for(int i =0 ; i <3 ;i++)
{
cin >> roll[i];
}
cout<<"Roll Array Preview" <<endl ;
for(int i =0 ; i <element ;i++)
{
cout << roll[i] <<endl;
}
cout<<"After bouble Sorted" <<endl ;
for (int i = 0 ; i < element ;i++)
{
for (int j = 0 ; j < element -i ;j++)
{
if(roll[j]>roll[j+1])
{
int temp = roll[j];
roll[j]= roll[j+1];
roll[j+1]= temp ;
swap++;
}
noSwap = true ;
}
if(noSwap==true)
{
pass++ ;
break;
}
}
for(int i =0 ; i <element;i++)
{
cout << roll[i] <<endl;
}
cout << "Swap : " << swap <<endl;
cout << "pass : " << pass <<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment