文档介绍:(规格为A4纸或A3纸折叠)
佛山科学技术学院(用四号宋体)
实验报告(用小二号黑体)
课程名称数据结构实验
实验项目实现队列和栈的各种算法及操作
专业班级 10网络工程(2)班姓名___蒲永毅学号 23
指导教师成绩日期 2011/11/7
(用小四号宋体)
一、目的和要求
1. 理解队列和栈的顺序存储结构和链式存储结构。通过本实验,熟悉队列、栈的结构特点;
2. 熟悉队列、栈结构上的操作与算法的实现。
 
二、实验内容
1. 队列的基本操作和应用。
2. 栈的基本操作和应用。
 
三、仪器、设备和材料
1. 适合实验要求的计算机系统
2. C语言编程平台。
四、实验原理
队列与栈是一种操作受限制的线性表,在了解线性表的基本原理的基础上,理解与完成此项实验。
 
五、实验步骤
1. 采用队列的顺序存储结构,
,出队,入队等基本操作。
3. 采用栈的链式存储结构
4. 用菜单的形式完成栈的出栈、入栈等基本操作。
六、程序算法
源代码:
#include <>
#include <>
#define OVERFLOW -2
#define ERROR 0
#define OK 1
#define MAX 100 //栈的最大值
typedef int SElemType;
typedef int QElemType;
typedef struct
{SElemType *base;
SElemType *top;
}SqStack;
SqStack InitStacka( ) //顺序存储实现栈的初始化
{SqStack S;
=(SElemType *)malloc(MAX*sizeof(SElemType));
if(!) exit(OVERFLOW);
=;
return(S);
}
void Pusha(SqStack &S,int x) //顺序存储实现栈的入栈操作
{if(->=MAX) exit(OVERFLOW);
*++=x;
}
void Popa(SqStack &S) //顺序存储实现栈的出栈操作
{SElemType *p;
int x;
if(==) return ;
else {p=;
x=*--;
printf("\t删除的栈顶元素是%d\n\t出栈操作完成后的栈为:\n",x);
}
}
void printa(SqStack S) //输出
{SElemType *p;
p=;
printf("\t");
while(p!=)
{printf("%d ",*(p++));}
printf("\n");
}
typedef struct SqNode
{SElemType data;
SqNode *Link;
}*Sqptr,NODE;
typedef struct
{Sqptr top;
}Stack;
Stac