|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define STACKSIZE 100
#define MAXSIZE 100
typedef struct{
int data[STACKSIZE];
int top;
}SeqStack,*PSeqStack;
//1.初始化栈
PSeqStack Init_SeqStack(){
PSeqStack S;
S=(PSeqStack)malloc(sizeof(SeqStack));
if(S!=NULL)
S->top=-1;
return S;
}
//2.判断栈空
int Empty_SeqStack(PSeqStack S)
{
if(S->top==-1)
return 1;
else return 0;
}
//3.x进栈
int Push_SeqStack(PSeqStack S,int x)
{
if(S->top==STACKSIZE-1)
return 0;
else{
S->top++;
S->data[S->top]=x;
return 1;
}
}
//4.出栈--栈顶元素赋给x
int Pop_SeqStack(PSeqStack S,int *x)
{
if(Empty_SeqStack(S)==1)
return 0;
else{
*x=S->data[S->top];
S->top--;
return 1;
}
}
//5.取栈顶元素返回
int GetTop_SeqStack(PSeqStack S)
{
if(Empty_SeqStack(S)==1){
printf("Empty Stack!\n");
return -1;
}
else
return S->data[S->top];
}
//6.销毁栈
int Destory_SeqStack(PSeqStack *S)
{
if(*S){
free(*S);
*S=NULL;
return 1;
}
return 0;
}
/*int main()
{
PSeqStack s;
int x=0;
s=Init_SeqStack();
Push_SeqStack(s,1);
Push_SeqStack(s,2);
Push_SeqStack(s,3);
Push_SeqStack(s,4);
printf("Top:%d ",GetTop_SeqStack(s));
Destory_SeqStack(&s);
return 1;
}*/
int main()
{
|
|