#include<iostream.h>
#include<conio.h>
int search(int
*arr,int start,int end)
{
int max=arr[start];
int pos;
for(int i=start+1;i<=end;i++)
{
if(max<arr[i])
{
pos=i;
max=arr[i];
}
}
return pos;
}
void main()
{
clrscr();
int array[]={1,3,5,4,3,2,6,7,6,8,9};
int len=11;
int pos;
cout<<array[0]<<" ";
for(int i=0;i<len;)
{
pos=search(array,i,array[i]+i);
i=pos;
cout<<" "<<array[pos];
if(len-i>array[i])
continue;
else
break;
}
getch();
}
No comments:
Post a Comment