2022年数据结构栈和队列的基本操作实现及其应用归纳 .pdf
《2022年数据结构栈和队列的基本操作实现及其应用归纳 .pdf》由会员分享,可在线阅读,更多相关《2022年数据结构栈和队列的基本操作实现及其应用归纳 .pdf(8页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、实验 二栈和队列的基本操作实现及其应用一、实验目的1、熟练掌握栈和队列的基本操作在两种存储结构上的实现。2、会用栈和队列解决简单的实际问题。二、实验内容(可任选或全做)题目一、试写一个算法,判断依次读入的一个以 为结束符的字符序列,是否为 回文。 所谓 “回文 “是 指正向 读和 反向读 都一 样的一 字符 串, 如“321123”或“ableelba ” 。相关常量及结构定义:# define STACK_INIT_SIZE 100 # define STACKINCREMENT 10 # define OK 1 # define ERROR 0 typedef int SElemType;
2、 / 栈类型定义typedef struct SqStack SElemType *base; SElemType *top; int stacksize; SqStack; 设计相关函数声明:判断函数: int IsReverse() 栈:int InitStack(SqStack &S ) int Push(SqStack &S, SElemType e ) int Pop(SqStack &S,SElemType &e) int StackEmpty(s) 题目二、编程模拟队列的管理,主要包括:出队列、入队、统计队列的长度、查找队列某个元素e、及输出队列中元素。 实现提示 :参考教材循环
3、队列的有关算法,其中后两个算法参考顺序表的实现。题目三、Rails 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 8 页 - - - - - - - - - Description There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortunately, funds
4、were extremely limited that time. It was possible to establish only a surface track. Moreover, it turned out that the station could be only a dead-end one (see picture) and due to lack of available space it could have only one track. The local tradition is that every train arriving from the directio
5、n A continues in the direction B with coaches reorganized in some way. Assume that the train arriving from the direction A has N = 1000 coaches numbered in increasing order 1, 2, ., N. The chief for train reorganizations must know whether it is possible to marshal coaches continuing in the direction
6、 B so that their order will be a1, a2, ., aN. Help him and write a program that decides whether it is possible to get the required order of coaches. You can assume that single coaches can be disconnected from the train before they enter the station and that they can move themselves until they are on
7、 the track in the direction B. You can also suppose that at any time there can be located as many coaches as necessary in the station. But once a coach has entered the station it cannot return to the track in the direction A and also once it has left the station in the direction B it cannot return b
8、ack to the station. Input The input consists of blocks of lines. Each block except the last describes one train and possibly more requirements for its reorganization. In the first line of the block there is the integer N described above. In each of the next lines of the block there is a permutation
9、of 1, 2, ., N. The last line of the block contains just 0. The last block consists of just one line containing 0. Output 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 8 页 - - - - - - - - - The output contains the lines corresponding to the lines with permutati
10、ons in the input. A line of the output contains Yes if it is possible to marshal the coaches in the order required on the corresponding line of the input. Otherwise it contains No. In addition, there is one empty line after the lines corresponding to one block of the input. There is no line in the o
11、utput corresponding to the last null block of the input. Sample Input 5 1 2 3 4 5 5 4 1 2 3 0 6 6 5 4 3 2 1 0 0 Sample Output Yes No Yes 题目四、 Sliding Window Description An array of size n 106 is given to you. There is a sliding window of size k which is moving from the very left of the array to the
12、very right. You can only see the knumbers in the window. Each time the sliding window moves rightwards by one position. Following is an example: The array is 1 3 -1 -3 5 3 6 7, and k is 3. Window position Minimum value Maximum value 1 3 -1 -3 5 3 6 7 -13 1 3 -1 -3 5 3 6 7 -33 1 3 -1 -3 5 3 6 7 -35 1
13、 3 -1 -3 5 3 6 7 -35 1 3 -1 -3 5 3 6 7 36名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 8 页 - - - - - - - - - 1 3 -1 -3 5 3 6 737Your task is to determine the maximum and minimum values in the sliding window at each position. Input The input consists of two lin
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年数据结构栈和队列的基本操作实现及其应用归纳 2022 数据结构 队列 基本 操作 实现 及其 应用 归纳
限制150内