Find the smallest window


#1

write a program:
Give an array of integers,find the smallest window in array sorting which will make the entire array sorted in increasing order.


#2

this problem can be solved by using binary heaps,
it is optimal way to solve above problem. we can use min heap to get minimum element from the array.

#include<stdio.h>
int l=-1,a[100],n,temp;
void heapup(int c)
{
int p=(c-1)/2;
if(c==0)
return;
if(a[p]>a[c])
{
temp=a[p];
a[p]=a[c];
a[c]=temp;
heapup(p);
}
}
void ins()
{
printf("enter data");
scanf("%d",&n);
a[++l]=n;
heapup(l);

    }
    void print()
    {
    for(n=0;n<=l;n++)
    printf("%d  ",a[n]);
    }
    main()
    {
    while(1)
    {
    printf("1.ins 2.print elements in increasing order 3.exit");
    scanf("%d",&n);
    switch(n)
    {
    case 1:ins();
    break;
    case 2:print();
    break;
    default:exit(0);
    }
    }
    }