实现顺序栈的各种基本运算的算法C语言,实验3.1实现顺序栈各种基本运算的算法.doc...

实验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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值