2022 年国家开放大学数据结构(本)形考任务实践活动 3 实验3 栈、队列、递归设计 数据结构课程实验报告 学生姓名 学 号 班 级 指导老师 实验名称 栈、队列、递归程序设计 实验成绩 实验报告 实 验 概 述 实验目的: 编写一个算法,输出指定栈中的栈底元素,并使得原栈中的元素倒置。 实验要求: (1)正确理解栈的先进后出的操作特点,建立初始栈,通过相关操作显示栈底元素。 (2)程序中要表达出建栈过程和取出栈底元素后恢复栈的入栈过程,按堆栈的操作 规那么打印结果栈中的元素。 实验基本原理: (1)采用顺序栈,即用数组存储栈元素。 (2)设定一个临时队列,用来存放从初始栈中出栈的元素。 (3)取出栈底元素后,将队列中的元素逐一出队并压入初始栈中。 卖 验 内 容 实验设计思路、步骤和方法等: (1)根据栈的先进后出特点,来进行实验 (2)建立顺序栈、临时队列、依次取出压入栈 实验过程(实验中涉及的记录、数据、分析): ttinclude ^include #define MaxSize 100 typedef int ElemType; typedef struct ( ElemType dataLMaxSize]; int top; } SeqStack; typedef struct ( ElemType data[MaxSize]; int front, rear; )SeqQueue; void InitStack(SeqStack *s); int StackEmpty(SeqStack *s); int StackFull(SeqStack *s); void Push(SeqStack *s,ElemType x); printf("\n"); ElemType Pop(SeqStack *s); ElemType GetTop(SeqStack *s); void DispStack(SeqStack *s); void DispBottom(SeqStack *s); void Ini tQueue(SeqQueue *sq); int QueueEmpty(SeqQueue *sq); void InQueue(SeqQueue *sq, ElemType x); ElemType OutQueue(SeqQueue *sq, ElemType x); ElemType GetQueue(SeqQueue *sq) void main() ( SeqStack *s; SeqQueue *sq; ElemType x; int n, i; printf ("(1)初始化栈 s\n"); s=(SeqStack *)malloc(sizeof(SeqStack)): Ini tStack (s); printf ("(2)栈为%s\n”, (StackEmpty(s)?"空":"非空")); printf("(3)输入要进栈的数据个数:”); scanf (飞 d”, &n): printf ("依次输入进栈的%d 个整数 n); for(i=0; i