![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构学习
文章平均质量分 82
老问题
这个作者很懒,什么都没留下…
展开
-
队列的链表实现
#include#include#includeconst int max = 10; typedef struct Node * ProToNode;/* ProToNode 相当与struct Node * */struct Node{/* 队列中的结点 */ int num; ProToNode next;};typedef ProToNode Position;/原创 2016-11-28 21:22:35 · 483 阅读 · 0 评论 -
5-5 堆中的路径 (25分)
5-5 堆中的路径 (25分)将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数NN和MM(\le 1000≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的NN个要被插入一个初始为空的小顶堆的整数。最后一行给出原创 2017-01-14 17:03:18 · 439 阅读 · 0 评论 -
5-8 File Transfer (25分)
We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another. Is it possible to send a file from any computer原创 2017-01-15 19:44:30 · 362 阅读 · 0 评论 -
5-7 Complete Binary Search Tree (30分)
5-7 Complete Binary Search Tree (30分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only node原创 2017-01-11 10:08:08 · 392 阅读 · 0 评论 -
5-8 哈利·波特的考试 (25分)
5-8 哈利·波特的考试 (25分)哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahah原创 2017-02-08 19:10:07 · 633 阅读 · 0 评论 -
堆的操作(最大堆)
#include#include#includeusing namespace std;struct HNode{ int *data;/*存放元素的数组*/ int size;/*堆当前元素的个数*/ int capacity;/*堆的最大容量*/};typedef struct HNode * Heap;Heap create(int Maxsize){ Heap原创 2017-01-11 20:26:06 · 327 阅读 · 0 评论 -
5-9 Huffman Codes (30分)
In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Redundancy Codes", and hence printed his name in the history of computer science. As a professor who gives the f原创 2017-01-20 02:12:46 · 398 阅读 · 0 评论 -
5-11 Saving James Bond - Hard Version (30分)
5-11 Saving James Bond - Hard Version (30分)This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group o原创 2017-02-10 23:09:35 · 446 阅读 · 0 评论 -
图的遍历
/* 图的邻接矩阵表示法 */#include #include #include #define MaxVertexNum 100#define INFINITY 65535struct ENode{ int v1,v2;/*有向边 */ int weight;/*权重*/};typedef struct ENode *PtrToENode;struct GN原创 2017-01-21 18:26:33 · 280 阅读 · 0 评论 -
5-10 公路村村通 (30分)
5-10 公路村村通 (30分)现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本,求使每个村落都有公路连通所需要的最低成本。输入格式:输入数据包括城镇数目正整数NN(\le 1000≤1000)和候选道路数目MM(\le 3N≤3N);随后的MM行对应MM条道路,每行给出3个正整数,分别是该条道路直接连通的两个城镇的编号以及该道路改原创 2017-02-20 21:55:28 · 2566 阅读 · 0 评论 -
5-9 旅游规划 (25分)
5-9 旅游规划 (25分)有了一张自驾旅游路线图,你会知道城市间的高速公路长度、以及该公路要收取的过路费。现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径。如果有若干条路径都是最短的,那么需要输出最便宜的一条路径。输入格式:输入说明:输入数据的第1行给出4个正整数NN、MM、SS、DD,其中NN(2\le N\le 5002≤N≤50原创 2017-02-11 23:49:03 · 568 阅读 · 0 评论 -
5-13 Insert or Merge (25分)
5-13 Insert or Merge (25分)According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort re原创 2017-03-01 18:55:30 · 507 阅读 · 0 评论 -
5-12 排序 (25分)
5-12 排序 (25分)给定NN个(长整型范围内的)整数,要求输出从小到大排序后的结果。本题旨在测试各种不同的排序算法在各种数据情况下的表现。各组测试数据特点如下:数据1:只有1个元素;数据2:11个不相同的整数,测试基本正确性;数据3:103个随机整数;数据4:104个随机整数;原创 2017-02-28 21:20:00 · 2881 阅读 · 0 评论 -
5-6 列出连通集 (25分)
5-6 列出连通集 (25分)给定一个有NN个顶点和EE条边的无向图,请用DFS和BFS分别列出其所有的连通集。假设顶点从0到N-1N−1编号。进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序访问邻接点。输入格式:输入第1行给出2个整数NN(0<N\le 100N≤10)和EE,分别是图的顶点数和边数。随后EE行,每行给出一条边的两个端点。每行中的原创 2017-01-30 00:13:27 · 377 阅读 · 0 评论 -
5-10 Saving James Bond - Easy Version (25分)
5-10 Saving James Bond - Easy Version (25分)This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group o原创 2017-01-30 14:59:16 · 643 阅读 · 0 评论 -
5-7 六度空间 (30分)
5-7 六度空间 (30分)“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。图1 六度空间示意图“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图原创 2017-02-02 18:37:36 · 431 阅读 · 0 评论 -
5-12 How Long Does It Take (25分)
5-12 How Long Does It Take (25分)Given the relations of all the activities of a project, you are supposed to find the earliest completion time of the project.Input Specification:Each in原创 2017-02-22 22:29:52 · 455 阅读 · 0 评论 -
5-14 电话聊天狂人 (25分)
5-14 电话聊天狂人 (25分)给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人。输入格式:输入首先给出正整数NN(\le 10^5≤105),为通话记录条数。随后NN行,每行给出一条通话记录。简单起见,这里只列出拨出方和接收方的11位数字构成的手机号码,其中以空格分隔。输出格式:在一行中给出聊天狂人的手机号码及其通话次数,其间以空格原创 2017-03-08 22:07:08 · 873 阅读 · 0 评论 -
集合的定义与查并操作
用的数据是:数组下标:0 1 2 3 4 5 6 7 8 9data: 1 2 3 4 5 6 7 8 9 10parent: -2 3 0 -2 0 -3 3 5 5 5#include#include#includeusing namespace std;typedef struct原创 2017-01-13 15:58:53 · 272 阅读 · 0 评论 -
5-4 是否同一棵二叉搜索树 (25分)(两种方法)
5-4 是否同一棵二叉搜索树 (25分)给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1行给出两原创 2017-01-05 09:22:40 · 414 阅读 · 0 评论 -
5-3 树的同构 (25分)
5-3 树的同构 (25分)给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。图1图2现给定两棵树,请你判断它们是否是同构的。输入格式:原创 2016-12-10 18:13:44 · 228 阅读 · 0 评论 -
5-4 List Leaves (25分)
5-4 List Leaves (25分)Given a tree, you are supposed to list all the leaves in the order of top down, and left to right.Input Specification:Each input file contains one test case. For原创 2016-12-11 20:58:19 · 176 阅读 · 0 评论 -
02-线性结构2 一元多项式的乘法与加法运算 (20分)
02-线性结构2 一元多项式的乘法与加法运算 (20分)设计函数分别求两个一元多项式的乘积与和。输入格式:输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式:输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空格分隔,原创 2016-12-02 01:56:42 · 317 阅读 · 0 评论 -
5-51 两个有序链表序列的合并 (20分)
5-51 两个有序链表序列的合并 (20分)已知两个非降序链表序列S1与S2,设计函数构造出S1与S2的并集新非降序链表S3。输入格式:输入分两行,分别在每行给出由若干个正整数构成的非降序序列,用-1−1表示序列的结尾(-1−1不属于这个序列)。数字用空格间隔。输出格式:在一行中输出合并后新的非降序链表,数字间用空格分开,结尾不能有多余空格;若新链表为空原创 2016-12-02 17:28:45 · 1859 阅读 · 0 评论 -
02-线性结构4 Pop Sequence (25分)
02-线性结构4 Pop Sequence (25分)Given a stack which can keep MM numbers at most. Push NN numbers in the order of 1, 2, 3, ..., NN and pop randomly. You are supposed to tell if a given seque原创 2016-12-03 20:22:55 · 319 阅读 · 1 评论 -
1086. Tree Traversals Again (25)
1086. Tree Traversals Again (25)时间限制200 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueAn inorder binary tree traversal can原创 2016-12-12 21:32:21 · 251 阅读 · 0 评论 -
1025. 反转链表 (25)
给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转。输入格式:每个输入包含1个测试用例。每个测试用例第1行给出第1个结点的地址、结点总个数正整数N(5)、以及正整数K(接下来有N行,每行格式为:Add原创 2016-12-04 23:19:20 · 302 阅读 · 0 评论 -
4-12 二叉搜索树的操作集 (30分)
4-12 二叉搜索树的操作集 (30分)本题要求实现给定二叉搜索树的5种常用操作。函数接口定义:BinTree Insert( BinTree BST, ElementType X );BinTree Delete( BinTree BST, ElementType X );Position Find( BinTree BST, ElementType X );P原创 2016-12-13 01:20:17 · 521 阅读 · 0 评论 -
5-18 银行业务队列简单模拟 (25分)
5-18 银行业务队列简单模拟 (25分)设某银行有A、B两个业务窗口,且处理业务的速度不一样,其中A窗口处理速度是B窗口的2倍 —— 即当A窗口每处理完2个顾客时,B窗口处理完1个顾客。给定到达银行的顾客序列,请按业务完成的顺序输出顾客序列。假定不考虑顾客先后到达的时间间隔,并且当不同窗口同时处理完2个顾客时,A窗口顾客优先输出。输入格式:输入为一行正整数,其中第原创 2016-12-05 17:30:04 · 6766 阅读 · 1 评论 -
5-19 求链式线性表的倒数第K项 (20分)
5-19 求链式线性表的倒数第K项 (20分)给定一系列正整数,请设计一个尽可能高效的算法,查找倒数第K个位置上的数字。输入格式:输入首先给出一个正整数K,随后是若干正整数,最后以一个负整数表示结尾(该负数不算在序列内,不要处理)。输出格式:输出倒数第K个位置上的数据。如果这个位置不存在,输出错误信息NULL。输入样例:4 1 2 3 4 5 6原创 2016-12-05 18:31:35 · 1287 阅读 · 1 评论 -
5-22 堆栈模拟队列 (25分)
5-22 堆栈模拟队列 (25分)设已知有两个堆栈S1和S2,请用这两个堆栈模拟出一个队列Q。所谓用堆栈模拟队列,实际上就是通过调用堆栈的下列操作函数:int IsFull(Stack S):判断堆栈S是否已满,返回1或0;int IsEmpty (Stack S ):判断堆栈S是否为空,返回1或0;void Push(Stack S, ElementType原创 2016-12-06 21:24:38 · 2974 阅读 · 0 评论 -
链表的基本操作
#include#include#includetypedef struct node{int num;struct node * pnext;}NODE, * PNODE;PNODE construction(void){int lenth,val;scanf("%d",&lenth);PNODE pHead = (PNODE)原创 2016-11-25 16:47:12 · 189 阅读 · 0 评论 -
链表游标实现
#include#include#include#includeconst int MAX = 10;struct node{ int num; int next;} CursorSpace[MAX];void init_CursorSpace(){ for(int i = 0; i < 9; i++) { CursorSpace[i].next = i + 1;原创 2016-11-25 16:56:59 · 316 阅读 · 0 评论 -
栈的数组实现
#include#include#include#includeconst int max = 5;typedef int position;struct stack{ int maxsize;/* 堆栈的最大容量 */ int *num; /* 储存数据的数组 */ int TopOfStack;/* 栈顶的指针 */};typedef struct st原创 2016-11-25 18:14:32 · 294 阅读 · 0 评论 -
栈的链表实现
#include#include#include#includestruct stack{ int num;/* 栈中的数字 */ struct stack * next;/* 下一个结点 */};typedef struct stack * Stack;/*创建一个栈的头结点,并反回该结点的指针*/Stack Create(){ Stack S = (Stack)原创 2016-11-25 20:12:46 · 259 阅读 · 0 评论 -
队列的数组实现
队列和栈有所不同,栈是先进后出,而队列是先进先出#include#include#includeconst int max = 10;struct queue{ int *num;/* 储存元素的指针 */ int rear;/* 队列的尾指针 */ int front;/* 队列的头指针 */ int maxsize;/* 队列的容量 */};typedef s原创 2016-11-28 17:08:37 · 228 阅读 · 0 评论 -
5-6 Root of AVL Tree (25分) (二叉平衡树的旋转操作)
5-6 Root of AVL Tree (25分)An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they dif原创 2016-12-16 19:15:25 · 548 阅读 · 0 评论 -
5-18 Hashing - Hard Version (30分)
5-18 Hashing - Hard Version (30分)Given a hash table of size NN, we can define a hash function . Suppose that the linear probing is used to solve collisions, we can easily obtain the status原创 2017-03-14 00:00:08 · 530 阅读 · 0 评论