#include<stdio.h>
#include<stdlib.h>
#include<strings.h>
struct node
{
int data;
struct node *next;
};
struct node *top=NULL;
void push(int pos)
{
struct node p;
p=(struct node)malloc(sizeof(struct node));
if(p==NULL)
printf("stack overflow\n");
else
{
if(top==NULL)
{
p->data=pos;
p->next=NULL;
top=p;
}
else
{
p->data=pos;
p->next=top;
top=p;
}
}
}
int pop()
{
struct node *p;
int x;
if(top==NULL)
{
printf("stack is empty\n");
}
else
{
p=top;
top=top->next;
x=p->data;
free(p);
}
return x;
}
int stackTop()
{
if(top==NULL)
return 0;
else
return top->data;
}
int isEmpty()
{
if(top==NULL)
return 1;
else
return 0;
}
void display()
{
struct node *p=top;
while§
{
printf("%d\n",p->data);
p=p->next;
}
}
int main()
{
int n;
scanf("%d",&n);
int temp1=n;
int *a=(int *)malloc(n*sizeof(int));
a[0]=0;
int *b=(int *)malloc(n*sizeof(int));
b[0]=0;
int i=1;
int j=1;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int zero;
scanf("%d",&zero);
/*for(int i=0; i<=n;i++)
printf("%d ",a[i]);
printf("\n");*/
int x=1;
while(x!=temp1)
{
if(stackTop()==x)
{
b[i]=pop();
i++;
x++;
}
else if(a[j]==x)
{
b[i++]=a[j++];
x++;
}
else
{
push(a[j]);
j++;
}
}
//display();
while(!isEmpty())
{
b[i++]=pop();
}
/*for(int i=0; i<=n;i++)
printf("%d ",b[i]);*/
for(int i=1; i<=n; i++)
{
if(b[i]!=i)
{printf("No");
return 0;
}
}
printf("Yes\n");
return 0;
}
…
The code works fine when i uncomment the boxes but is not working without those commands . why is it happening