#include<stdlib.h>
#include<stdio.h>
struct Node;
typedef struct Node *PNode;
typedef struct Node *pNext;
struct Node {
int info;
PNode link;
};
struct LinkStack
{
PNode top;
};
typedef struct LinkStack *PLinkStack;
PLinkStack createEmptyStack_link(void);
int isEmptyStack_link(PLinkStack plstack);
void push_link(PLinkStack plstack,int x);
void pop_link(PLinkStack plstack);
int top_link( PLinkStack plstack );
main()
{
PLinkStack L;
int A;
scanf("%d",&A);
L=createEmptyStack_link();
L=push_link(L,A);
pop_link(L);
top_link(L);
return L;
PLinkStack createEmptyStack_link(void)
{
PLinkStack plstack;
plstack=(PLinkStack)malloc(sizeof(struct LinkStack));
if(plstack!=NULL)
plstack->top=NULL;
else
printf("Out of space\n");
return plstack;
}
//判断栈是否为空栈
int isEmptyStack_link(PLinkStack plstack)
{
return (plstack->top==NULL);
}
//进栈
void push_link(PLinkStack plstack,int x)
{
PNode p;
p=(PNode)malloc(sizeof(struct Node));
if(p==NULL)
printf("Out of space\n");
else
p->info=x;
p->link=plstack->top;
plstack->top=p;
}
//出栈
void pop_link(PLinkStack plstack)
{
PNode p;
if(isEmptyStack_link(p))
printf("Empty top\n");
else
{
p=plstack->top;
plstack->top=plstack->top->link;
}}
int top_link( PLinkStack plstack )
/* 对非空栈求栈顶元素 */
{
if(plstack->top==NULL)
printf("Stack is empty\n");
else
return plstack->top->info;
}