![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
文章平均质量分 88
SydneyCarton_
这个作者很懒,什么都没留下…
展开
-
图-有向带权图的十字邻接表的数组实现
有向图需要用十字邻接表来表示。但用链表实现十字邻接表是非常苦恼的,代码很容易便会达到数百行。事实上有一种数组实现十字邻接表,不用指针便可解决有向带权图的问题(含重边,自环)。 理论上有向图解决了,无向图也可以被解决。输入格式4 51 4 94 3 81 2 52 4 61 3 7输入时点也可以是点的名称,此时需要建立点的名称字符串与点号的映射表。方法解读i 号点的第一条边边号为 first[i];i 号边的出点的下一条边边号为 next[i];特点① 以边号为主要操作对象。原创 2020-12-03 19:52:11 · 661 阅读 · 0 评论 -
堆-堆的基本概念与操作
堆(heap)又名优先队列(priority queue),是一种特殊的树。1. 堆的两个性质:① structure property: 是一个完全二叉树;因此可用数组表示,BT[n+1]的形式,BT[0]为dummy.② order property: (min heap为例,大小关系变反之后则为max heap)表述一:每个子树的根的值都比子树中其他值小;表述二:每个结点的值都比左右子小;表述三:从根到任何叶的(唯一)路径上,结点的值递增;2. 堆的父子结点3. 堆的基本操作(原创 2020-11-18 21:40:14 · 717 阅读 · 0 评论 -
树-表达式树与prefix/infix/postfix的转换
众所周知· 前缀/中缀/后缀表达式中的任意一个,都可以唯一确定一个表达式树;· 对于表达式树进行前序/后序遍历可以得到前缀/后缀表达式,进行每次加括号的中序遍历可以得到中缀表达式。· prefix, infix, postfix, syntax tree四者两两均构成双射。我们这里来讨论如何实现由三种表达式构造表达式树。为了简便,我们只考虑中缀表达式带有全部括号的情况。(若完全不带有括号,则它根本不是中缀表达式,也不对应着唯一的表达式树。若只带有必要的括号,则可以先用其他方法将其变成带有全部括号的原创 2020-11-15 20:23:19 · 578 阅读 · 0 评论 -
不相交集-PTA-数组实现不相交集及Union, Find, Check操作
File TransferWe 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 on the network to any other?Input Specifi原创 2020-12-04 13:35:04 · 289 阅读 · 0 评论 -
链表-PTA-链表的游标实现
Merging Linked ListsGiven two singly linked lists L1=a1→a2→⋯→an−1→an and L2=b1→b2→⋯→bm−1→bm. If n≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a list like a1→a2→bm→a3→a4原创 2020-11-14 15:13:24 · 293 阅读 · 0 评论 -
二叉树-PTA-递归构造完全二叉搜索树
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 nodes with keys less than the node’s key.The right subtree of a node contains only nodes with keys greater than原创 2020-11-14 15:13:13 · 522 阅读 · 1 评论 -
树-PTA-蛇形输出树[由中序后序构造树][递归求节点层数]
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences. And it is a simple standard routine to print the numbers in level-order. However原创 2020-11-14 15:12:59 · 167 阅读 · 0 评论 -
二叉树-递归计算某节点的层数/深度
该函数需要传入某已知节点、该节点的depth/level和目标节点,将返回目标节点的depth/level目标节点在已知节点的子树中才可以,通常传入整个树,如下 level = Rec_GetLevel(t, 1, target);#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#define NOT_FOUND -999typedef struct node{ int Element;原创 2020-10-14 13:38:26 · 3000 阅读 · 0 评论 -
双向队列-PTA-双向队列的插删
A “deque” is a data structure consisting of a list of items, on which the following operations are possible:Push(X,D): Insert item X on the front end of deque D.Pop(D): Remove the front item from deque D and return it.Inject(X,D): Insert item X on the r原创 2020-11-14 15:11:12 · 183 阅读 · 0 评论 -
栈-PTA-判断给定出栈结果是否可实现
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obtain原创 2020-11-14 15:10:59 · 160 阅读 · 0 评论 -
栈-PTA-支持负数与小数的“atoi”函数
Format of functions:ElementType EvalPostfix( char *expr );where expr points to a string that stores the postfix expression. It is guaranteed that there is exactly one space between any two operators or operands. The function EvalPostfix is supposed to r原创 2020-09-28 19:17:45 · 364 阅读 · 0 评论 -
图-PTA-寻找强连通分支&寻找关节点 思路的相似性
Write a program to find the strongly connected components in a digraph.Format of functions:void StronglyConnectedComponents( Graph G, void (*visit)(Vertex V) );where Graph is defined as the following:typedef struct VNode *PtrToVNode;struct VNode {原创 2021-01-13 17:48:33 · 1113 阅读 · 0 评论 -
图-PTA-判断给定序列是否是拓扑排序
Is Topological OrderWrite a program to test if a give sequence Seq is a topological order of a given graph Graph.Format of functions:bool IsTopSeq( LGraph Graph, Vertex Seq[] );where LGraph is defined as the following:typedef struct AdjVNode *PtrToAd原创 2021-01-13 16:59:19 · 1234 阅读 · 0 评论