急!求助!
对栈 的操作,不知道错哪里!#include<stdio.h>
#define maxsize 20
struct stack
{int data[maxsize];
int top[2];
};
typedef struct stack STACK
void initstack(STACK *s)
{s->top[0]=-1;
s->top[1]=maxsize;
}
int push(STACK *s,int x,int k)
{if(s->top[0]==s->top[1])
{printf("\nstack is full!");
return 0;
}
if(k==0)
{s->top[0]++;
s->data[s->top[0]]=x;
}
else{s->top[1]--;
s->data[s->top[1]]=x;
}
return 1;
}
int pop(STACK *s,int k,int *x)
{if((k==0)&&(s->top[0]=-1))
{printf("\nstack is free!");
return 0;
}
if((k==1)&&(s->top[1]=maxsize))
{printf("\nstack is free!");
return 0;
}
if(k==0)
{*x=s->data[s->top[0]];
s->top[0]--;
}
else{*x=s->data[s->top[1]];
s->top[1]++;
}
return 1;
}
void print(STACK *s)
{printf("The num of s1 are:\n");
while(s->top[0]!=-1)
{printf("%d ",s->data[s->top[0]]);
s->top[0]++;
}
printf("\n");
printf("The num of s2 are:\n");
while(s->top[1]!=maxsize)
{printf("%d",s->data[s->top[1]]);
s->top[1]--;
}
printf("\n");
}
void main()
{int i=0,x,k,*p;
STACK *s;
initstack(*s);
printf("input 8 num into s1:\n");
while(i<8)
{scanf("%d",&s->data[i]);
s->top[0];
i++;
}
printf("input 8 num into s2:\n");
while(i<8)
{scanf("%d",&s->data[maxsize-1-i]);
s->top[1]--;
i++;
}
print(*s);
printf("input the num pushed into s1:\n")
scanf("%d",&x);
k=0;
push(*s,x,k);
print(*s);
printf("now,delete the num of s2:\n");
k=1;
pop(*s,k);
print(*s);
}