Created
February 26, 2015 12:05
-
-
Save rohith2506/844333e4fd6bdb575778 to your computer and use it in GitHub Desktop.
Pancake sorting
This file contains hidden or 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
| //http://www.geeksforgeeks.org/pancake-sorting/ | |
| void flip(vector<int> v, int i){ | |
| int temp, start = 0; | |
| while(start < i){ | |
| int temp = v[start]; | |
| v[start] = v[i]; | |
| v[i] = temp; | |
| start++; | |
| i--; | |
| } | |
| } | |
| int findmax(vector<int>, int end){ | |
| int maxindex = 0; | |
| int maxvalue = v[end]; | |
| for(int i=0; i<end; i++){ | |
| if(v[i] > maxvalue){ | |
| maxi = i; | |
| maxvalue = v[i]; | |
| } | |
| } | |
| return maxi; | |
| } | |
| void pancake(vector<int> v){ | |
| for(int cur = n; cur >=0; cur--){ | |
| int maxindex = findmax(v, cur); | |
| filp(v,maxindex); | |
| flip(v,cur-1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment