Created
October 20, 2014 17:22
-
-
Save shemul/bbda8c7ee569ea838dac to your computer and use it in GitHub Desktop.
bouble sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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