实验3.1实现顺序栈各种基本运算的算法
实验1.实验目的
(1)掌握的定义、的方法及基本操作。
(2)掌握将算法在VC++6.0语言环境下实现。
(1)复习的定义,掌握的方法及操作。
(2)复习C语言中数组及结构体的概念、定义方式。
(3)实验的计算机中安装了Microsoft VC++ 6.0。
编写一个控制台
#include
#include
#define MaxSize 100
typedef char ElemType;
typedef struct
{
ElemType elem[MaxSize];
int top;/*栈指针*/
} SqStack;
void InitStack(SqStack *&s)///初始化栈s
{
s=(SqStack *)malloc(sizeof(SqStack));
s->top=-1;
}
void ClearStack(SqStack *&s)///释放栈s
{
}
int StackLength(SqStack *s)///求栈s长度
{
}
int StackEmpty(SqStack *s)///判断栈s是否为空栈
{
}
int Push(SqStack *&s,ElemType e)///进栈元素e
{
return 1;
}
int Pop(SqStack *&s,ElemType &e)///出栈一个元素
{
return 1;
}
int GetTop(SqStack *s,ElemType &e)///取栈顶元素
{
return 1;
}
void DispStack(SqStack *s)///从栈顶到栈底输出元素
{
}
#include
#include
#define MaxSize 100
typedef char ElemType;
typedef struct
{
ElemType elem[MaxSize];
int top;/*栈指针*/
} SqStack;
extern void InitStack(SqStack *&s);
extern void ClearStack(SqStack *&s);
extern int StackLength(SqStack *s);
extern int StackEmpty(SqStack *s);
extern int Push(SqStack *&s,ElemType e);
extern int Pop(SqStack *&s,ElemType &e);
extern int GetTop(SqStack *s,ElemType &e);
extern void DispStack(SqStack *s);
void main()
{
ElemType e;
SqStack *s;
printf("(1)初始化栈s\n");
InitStack(s);
printf("(2)栈为%s\n",(StackEmpty(s)?"空":"非空"));
printf("(3)依次进栈元素a,b,c,d,e\n");
Push(s,'a');
Push(s,'b');
Push(s,'c');
Push(s,'d');
Push(s,'e');
ClearStack(s);
}
2