Write routines to implement two stacks using only one array. Your stack routines should not declare an overflow unless every slot in the array is used.
Format of functions:
Stack CreateStack( int MaxElements );
int IsEmpty( Stack S, int Stacknum );
int IsFull( Stack S );
int Push( ElementType X, Stack S, int Stacknum );
ElementType Top_Pop( Stack S, int Stacknum );
where int Stacknum is the index of a stack which is either 1 or 2; int MaxElements is the size of the stack array; and Stack is defined as the following:
typedef struct StackRecord *Stack;
struct StackRecord {
int Capacity; /* maximum size of the stack array */
int Top1; /* top pointer for Stack 1 */
int Top2; /* top pointer for Stack 2 */
ElementType *Array; /* space for the two stacks */
}
Note: Push is supposed to return 1 if the operation can be done successfully, or 0 if fails. If the stack is empty,

这篇博客探讨如何利用一个数组来实现两个独立的栈。内容包括设计相应的push和pop操作,确保在数组满载时才报溢出错误,并提供了一个示例程序说明栈操作的逻辑。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



