/*Now there is an array we can define a subarray of arrays such as array 1 3 4 2 5 8 7 Its sub-arrays can be 1 3 4 3 4 2 5 and so on, write an algorithm to find a subarray this subarray increment does not decrease and is the oldest array that satisfies the increment.*/#include<iostream>#include<cstdlib>#include<ctime>using namespacestd;template<typename t>voidInit (T array[],intLen) {Srand (unsignedint) (Time (NULL))); for(intI=0; i<len; i++) {Array[i]= rand ()%Ten-5; }}template<typename t>voidPrint_array (T array[],intLen) { for(intI=0; i<len; i++) {cout<<array[i]<<" "; } cout<<Endl;} Template<typename t>voidFind_sub_array (T array[],intLen) { intret = (Len >1); if(ret) {intsum =1; intCur =1; intindex =0; intCI =0; T Ele= array[0]; for(intI=1; i<len; i++) { if(Ele <=Array[i]) {cur++; } Else{cur=1; CI=i; } if(Cur >sum) {Sum=cur; Index=CI; } ele=Array[i]; } print_array (Array+index, SUM); }}intMain () {intarray[Ten] = {0}; intMax_sum =0; Init (Array,Ten); Print_array (Array,Ten); Find_sub_array (Array,Ten); return 0;}
C-Pen question (ii)