#Given an unsorted array , sort the array when with only using the operation flip(a,i). #flip(a,i) means reversing the array a from index 0 to i #Time-complexity: O(n^2), In-place, Not-stable =begin Algorithm:Find the max element index max_i,flip(a,i),flip(0,len-1)(now max is at its right position), decrease len by 1 =end def pancake_sort(a) n=a.length for i in n.downto(2) max_i=find_max(a,i) unless max_i == i-1 flip(a,max_i) flip(a,i-1) end end return a end def find_max(a,len) max_i=0 i=1 while ia[max_i] i+=1 end return max_i end def flip(a,len) start=0 while start [1, 1, 2, 3, 5, 6, 7, 7, 8, 9]