特点:
#include<stdio.h>
#include<stdlib.h>
#define MaxSize 64
typedef int datatype;
typedef struct
{
datatype data[MaxSize];
int top;
}seqstack;
seqstack* InitStack(seqstack* s)
{
s=(seqstack*)malloc(sizeof(seqstack));
s->top=-1;
return s;
}
int Push(seqstack *sstack,datatype x)//入栈;
{
if(sstack->top==MaxSize-1)
{
printf("stack full!\n");
return -1;
}
sstack->top++;
sstack->data[sstack->top]=x;
return 1;
}
int Pop(seqstack *sstack)//出栈;
{
if(sstack->top==-1)
{
printf("OVER->Top = %d",sstack->top);
return -1;
}
printf("Pop %d\n",sstack->data[sstack->top]);
sstack->top--;
return 1;
}
typedef struct node
{
datatype data;
struct node * next;
}LinkStack;
LinkStack *top;
LinkStack* Push(LinkStack* top,datatype x)
{
LinkStack* p;
p = (LinkStack)malloc(sizeof(LinkStack));
p->data = x;
p->next = top->next;
top=p;
return top;
}
LinkStack* Pop(LinkStack* top)
{
LinkStack* q;
if(!top){
printf("Stack null!");
return NULL;
}
q=top->next;
top=top->next;
free(q);
return top;
}