- typedef struct SNode *PtrToSNode;
- struct SNode {
- ElementType Data;
- PtrToSNode Next;
- };
- typedef PtrToSNode Stack;
-
- Stack CreateStack( )
- {
- Stack S;
-
- S = (Stack)malloc(sizeof(struct SNode));
- S->Next = NULL;
- return S;
- }
-
- bool IsEmpty ( Stack S )
- {
- return ( S->Next == NULL );
- }
-
- bool Push( Stack S, ElementType X )
- {
- PtrToSNode TmpCell;
-
- TmpCell = (PtrToSNode)malloc(sizeof(struct SNode));
- TmpCell->Data = X;
- TmpCell->Next = S->Next;
- S->Next = TmpCell;
- return true;
- }
-
- ElementType Pop( Stack S )
- {
- PtrToSNode FirstCell;
- ElementType TopElem;
-
- if( IsEmpty(S) ) {
- printf("堆栈空");
- return ERROR;
- }
- else {
- FirstCell = S->Next;
- TopElem = FirstCell->Data;
- S->Next = FirstCell->Next;
- free(FirstCell);
- return TopElem;
- }
- }
posted on
2019-08-05 21:39
董南
阅读(
281)
评论()
编辑
收藏
举报