#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 30
#define OK 1
#define ERROR -1
#define False 0
typedef int SElemType;
typedef int Status;
typedef struct stackNode* LinktackPtr;
typedef struct stackNode
{
SElemType data;
LinktackPtr next;
}stackNode;
typedef struct LinkStack
{
LinktackPtr top;
int count;
}LinkStack;
Status StackEmpty(LinkStack* S)
{
if (S->top)
return OK;
else
{
return False;
}
}
Status Push(LinkStack* S, SElemType item)
{
LinktackPtr ptr = (LinktackPtr)malloc(sizeof(stackNode));
ptr->next = S->top;
S->top = ptr;
S->count++;
return OK;
}
Status Pop(LinkStack* S, SElemType item)
{
LinktackPtr ptr;
if (StackEmpty(S))
{
return ERROR;
}
item = S->top->data;
ptr = S->top;
S->top = S->top->next;
free(ptr);
S->count--;
return OK;
}
typedef struct SNode* Stack;
struct SNode
{
SElemType Data;
struct SNode* Next;
};
Stack CreateStack()
{
Stack s;
s = (Stack)malloc(sizeof(struct SNode));
s->Next = NULL;
return s;
}
Status ISEmpty(Stack S)
{
return (S->Next == NULL);
}
Status Push_(Stack S, SElemType item)
{
struct SNode* TmpCell;
TmpCell = (Stack)malloc(sizeof(struct SNode));
TmpCell->Data = item;
TmpCell->Next = S->Next;
S->Next = TmpCell;
return OK;
}
Status Pop_(Stack S)
{
struct SNode* FirstCell;
SElemType TopElem;
if (ISEmpty(S))
{
return ERROR;
}
else
{
FirstCell = S->Next;
S->Next = FirstCell->Next;
TopElem = FirstCell->Data;
free(FirstCell);
return TopElem;
}
}