/************************************************************************/ /* given an array of integer, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n-m that is find the smallest such sequence eg. input: 1,2,4,7,10,11,12,7,12,6,7,16,18,19 output: (3,10)*/ /* basic idea: using two stacks to remember the numbers, one is from head and the other is from the tail. */ /************************************************************************/ #include <iostream> #include <stack> using namespace std; int getindiceFhead( int a[], int length); int getindiceFtail( int a[], int length); void getIndices( int a[], int length) { int m, n; m = getindiceFhead(a, length); n = getindiceFtail(a, length) - m; cout<< "(" <<m<< ", " <...
Comments
Post a Comment