#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
#define SizeMax 105
typedef char ElemType;
typedef struct
{
ElemType data[SizeMax];
int top;
} SqStack;
void InitStack(SqStack *&s) //建立栈
{
s=(SqStack*)malloc(sizeof(SqStack));
memset(s->data,0,sizeof(SqStack));
s->top=-1;
}
int StackEmpty(SqStack *s) //判断是否为空
{
return s->top==-1;
}
void Push(SqStack *&s,ElemType x) //把x元素压入栈
{
s->top++;
s->data[s->top]=x;
}
int Length(SqStack *s) //输出长度
{
return s->top+1;
}
void PrintStack(SqStack *s) //输出栈
{
for(int i=(int)strlen(s->data)-1; i>=0; i--)
printf("%c",s->data[i]);
printf("\n");
}
void Print(SqStack *s) // //输出栈
{
PrintStack(s);
}
void DestroyStack(SqStack *&s)//销毁栈
{
free(s);
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
#define SizeMax 105
typedef char ElemType;
typedef struct
{
ElemType data[SizeMax];
int top;
} SqStack;
void InitStack(SqStack *&s) //建立栈
{
s=(SqStack*)malloc(sizeof(SqStack));
memset(s->data,0,sizeof(SqStack));
s->top=-1;
}
int StackEmpty(SqStack *s) //判断是否为空
{
return s->top==-1;
}
void Push(SqStack *&s,ElemType x) //把x元素压入栈
{
s->top++;
s->data[s->top]=x;
}
int Length(SqStack *s) //输出长度
{
return s->top+1;
}
void PrintStack(SqStack *s) //输出栈
{
for(int i=(int)strlen(s->data)-1; i>=0; i--)
printf("%c",s->data[i]);
printf("\n");
}
void Print(SqStack *s) // //输出栈
{
PrintStack(s);
}
void DestroyStack(SqStack *&s)//销毁栈
{
free(s);
}