Optimized Pancake sort

The algorithm is best described recursively: procedure opti_pancake_sort(array arr, int n) do if n > 1 do int m = floor(n/2) opti_pancake_sort(arr, m)      rotate(arr, 0, m, n-m) opti_pancake_sort(arr, n-m) merge(arr, m, n-m) end if end
 * 1) Divide array $$A$$ into $$BC$$ and sort $$B$$ recursively
 * 2) Rotate $$BC \rightarrow CB$$ and sort $$C$$ recursively
 * 3) Merge $$C$$ and $$B$$ using an in-place recursive pancake merge