请利用两个栈S1和S2来模拟一个队列。请高手们检查我写程序的错误.谢谢

#include "stdio.h"
#define MAXSIZE 100 /* 宏定义 */

typedef struct stack /*定义栈结构体类型*/
{
int data[MAXSIZE];
int top;
}Stack;
int x;
Stack s1,s2; /*栈变量*/
int PUSH(Stack s,int x) /*入栈子函数*/
{ s.data[s1.top]=x;
s.top++;
return 1;
}

int POP(Stack s,int x) /*出栈子函数*/
{ s.top--;
x=s.data[s.top];
return 1;
}

int Sempty(Stack s )/*栈空子函数*/
{if(s.top==0)
{
return 1;
}
else
return 0;
}

int enpueue(Stack s1,int x)/*入队子函数*/
{ if (s1.top==MAXSIZE&&!Sempty(s2)) /* s1满s2非空,这时s1不能再入栈*/
{
printf("zhanman");
return 0;
}
if (s1.top==MAXSIZE&&Sempty(s2)) /*若s2为空,先将s1出栈,元素再入栈到s2*/
{
while(!Sempty(s1))
{
POP(s1,x);
PUSH(s2,x);
}
}
PUSH(s1,x);
return 1;
}

void dequeue(Stack s2,Stack s1)
{
if(!Sempty(s2))
{
POP(s2,x);
printf("chudui:%d ",x);
}
else /*先将栈s1入s2中,再作出队操作*/
{
while(!Sempty(s1))
{
POP(s1,x);
PUSH(s2,x);
}
POP(s2,x);
printf("chudui:%d\n ",x);
}
}
int queue_empty(Stack s2,Stack s1)
{
if (Sempty(s1)&&Sempty(s2))
{
printf("duikong\n");
return(1);/*队列空*/
}
else
return 0;
}

第1个回答  2007-06-23
不是很明白。你说一下你得错误,
第2个回答  2007-06-25
我也不明白
相似回答