Created
October 20, 2014 17:41
-
-
Save shemul/f10de99ea877673562cd to your computer and use it in GitHub Desktop.
selection_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 selection Sorted" <<endl ; | |
for (int i = 0 ; i < element ;i++) | |
{ | |
for (int j = i+1 ; j < element ;j++) | |
{ | |
if(roll[i]>roll[j]) | |
{ | |
int temp = roll[i]; | |
roll[i]= roll[j]; | |
roll[j]= 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