- typedef int Position;
- struct SNode {
- ElementType *Data;
- Position Top;
- int MaxSize;
- };
- typedef struct SNode *Stack;
-
- Stack CreateStack( int MaxSize )
- {
- Stack S = (Stack)malloc(sizeof(struct SNode));
- S->Data = (ElementType *)malloc(MaxSize * sizeof(ElementType));
- S->Top = -1;
- S->MaxSize = MaxSize;
- return S;
- }
-
- bool IsFull( Stack S )
- {
- return (S->Top == S->MaxSize-1);
- }
-
- bool Push( Stack S, ElementType X )
- {
- if ( IsFull(S) ) {
- printf("堆栈满");
- return false;
- }
- else {
- S->Data[++(S->Top)] = X;
- return true;
- }
- }
-
- bool IsEmpty( Stack S )
- {
- return (S->Top == -1);
- }
-
- ElementType Pop( Stack S )
- {
- if ( IsEmpty(S) ) {
- printf("堆栈空");
- return ERROR;
- }
- else
- return ( S->Data[(S->Top)--] );
- }
posted on
2019-08-05 21:39
董南
阅读(
235)
评论()
编辑
收藏
举报