#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[]={10,2,6,4,5,3,7,8,9,1};
int n=sizeof(a)/sizeof(a[0]);
int i=0,j=1,k=j+1;
int loci=0,lock=0,pos1=0,pos2=0;
while(j<n)
{
if((a[j]>a[i] && i>0)
|| (a[j]<a[k] && k<n))
{
if(a[j]>a[i] && i>0)
i--;
else
loci=i;
if(a[j]<a[k] &&
k<n)
k++;
else
lock=k;
}
else
{
j=lock+2;
i=lock+1;
k=lock+3;
if(pos2-pos1<lock-loci)
{
pos2=lock;
pos1=loci;
}
}
}
for(int p=pos1;p<=pos2;p++)
cout<<" "<<a[p];
getch();
}
No comments:
Post a Comment