栈的creat函数
Stack CreateStack(int MaxSize)
{
Stack S = (Stack)malloc(sizeof(struct SNode));
S->Data = (ElementType*)malloc(MaxSize *sizeof(int) );
**S->MaxSize = MaxSize**
S->Top1 = -1;
S->Top2 = S->MaxSize ;//给S分配空间以后才能这样写!
return S;
}
Stack CreateStack(int MaxSize)
{
Stack S = (Stack)malloc(sizeof(struct SNode));
S->Data = (ElementType*)malloc(MaxSize *sizeof(int) );
S->Top1 = -1;
**S->Top2 = MaxSize ;**//或者是这样写
S->MaxSize = MaxSize;
return S;
}
堆栈模拟队列
有两个栈,往空间小的那个栈里存入数据,满了之后倒腾到另一个空间大的栈里
s2.push(s1.top()); s1.pop(); 这样的话由第二个栈输出,输出顺序就是队列输出的顺序。