请教:最近洗衣机和烘干机的DEAL。。。谢谢!# Living
a*y
1 楼
There is an external array of integers on which you can perform the
following operations in O(1) time.
1. get(int i) - returns the value at the index 'i' in the external array.
2. reverse( int i, int j) - returns the reverse of the array between index
positions i and j (including i and j).
example for reverse: consider an array {1,2,3,4,5}. reverse(0,2) will return
{3,2,1,4,5} and reverse(1,4) will return {1,5,4,3,2}.
Write a code to sort the external array. Mention the time and space
complexity for your code.
following operations in O(1) time.
1. get(int i) - returns the value at the index 'i' in the external array.
2. reverse( int i, int j) - returns the reverse of the array between index
positions i and j (including i and j).
example for reverse: consider an array {1,2,3,4,5}. reverse(0,2) will return
{3,2,1,4,5} and reverse(1,4) will return {1,5,4,3,2}.
Write a code to sort the external array. Mention the time and space
complexity for your code.