Skip to content

Instantly share code, notes, and snippets.

@rohith2506
Created February 26, 2015 12:05
Show Gist options
  • Select an option

  • Save rohith2506/844333e4fd6bdb575778 to your computer and use it in GitHub Desktop.

Select an option

Save rohith2506/844333e4fd6bdb575778 to your computer and use it in GitHub Desktop.
Pancake sorting
//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