1欢迎下载《数据结构》实验报告实验序号: 4 实验项目名称:栈的操作学号姓名专业、班实验地点指导教师实验时间一、实验目的及要求1
熟悉栈的基本概念;2
掌握栈的顺序存储结构;3.掌握栈的应用
二、实验设备(环境)及要求微型计算机;windows 操作系统;Microsoft Visual Studio 6
0集成开发环境
三、实验内容与步骤1
栈的顺序表表示和实现的如下:#include #define MaxSize 100 using namespace std; typedef int ElemType; typedef struct { ElemType data[MaxSize]; int top; }SqStack; void InitStack(SqStack *st) //初始化栈{ st->top=-1; } int StackEmpty(SqStack *st) //判断栈为空{ return (st->top==-1); } 精品文档
2欢迎下载void Push(SqStack *st,ElemType x) //元素进栈{ if(st->top==MaxSize-1) { printf("栈上溢出
\n"); } else { st->top++; //移动栈顶位置st->data[st->top]=x; //元素进栈} } void Pop(SqStack *st,ElemType &e) //出栈{ if(st->top==-1) { printf("栈下溢出 \n"); } else { e=st->data[st->top]; //元素出栈st->top--; //移动栈顶位置} } int main() { SqStack L; SqStack *st=&L; ElemType e; int i; InitStack(s