@Anuj & Piyush:
You didn't get the algo. It works on unsorted array also. You might have
missed the statement
*"else // next element is smaller than or equal to current element
reset curr_max to 1;*"
Here, the comment itself shows unsorted elements have been taken into
consideration.
If you still have the doubt let me know.
Here is code for you:
#include<cstdio>#define MAX_SIZE 10
int maxinterval(int a[],int size){
int curr_max=1, prev_max=1;
for(int k=0;k<size-1;k++)
{
if(a[k] < a[k+1])
{
curr_max++;
if(curr_max > prev_max)
{
prev_max=curr_max;
}
}
else
curr_max=1;
}
return prev_max;}
int main(){
int arr[MAX_SIZE] = {19,18,17,21,22,23,24};
printf("%d\n",maxinterval(arr,7) );
getchar();}
As expected it gives output 5.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.