
数据结构
qq_38191717
这个作者很懒,什么都没留下…
展开
-
二叉树
#include#include//******************************************************************定义队列//*************************定义二叉树左右形式struct bintree { int Data; struct bintree* Left; struct bintre原创 2017-04-07 23:27:32 · 260 阅读 · 0 评论 -
05-树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-10-21 22:40:51 · 360 阅读 · 0 评论 -
04-树4 是否同一棵二叉搜索树(25 分)
给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1行给出两个正整数N (≤)和L,分别是每个序列插入元素的个数和需原创 2017-10-12 20:19:54 · 212 阅读 · 0 评论 -
05-树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-10-22 23:44:25 · 322 阅读 · 0 评论 -
图的建立和BFS、DFS
#include#include#include#include#include#include#include#includeusing namespace std;ifstream inFile("C:\\Users\\DELL\\Desktop\\in.txt", ios::in);const int MaxVertexNum = 100;typedef int Ver原创 2017-10-24 22:38:58 · 272 阅读 · 0 评论 -
08-图7 公路村村通(30 分)
08-图7 公路村村通(30 分)现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本,求使每个村落都有公路连通所需要的最低成本。输入格式:输入数据包括城镇数目正整数N(≤1000)和候选道路数目M(≤3N);随后的M行对应M条道路,每行给出3个正整数,分别是该条道路直接连通的两个城镇的编号以及该道路改建的预算成本。为简单起见,城镇从1到N编号。原创 2017-11-11 16:44:09 · 810 阅读 · 0 评论 -
08-图8 How Long Does It Take(25 分)
08-图8 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 inp原创 2017-11-12 10:05:35 · 282 阅读 · 0 评论 -
07-图4 哈利·波特的考试(25 分)
哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahahehe。现在哈利·波特的手里有一本教材,里面列出原创 2017-11-02 22:07:46 · 406 阅读 · 0 评论 -
06-图2 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 of drug dealers. He was sent to a small piece of land原创 2017-10-26 20:40:58 · 213 阅读 · 0 评论 -
07-图5 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 of drug dealers. He was sent to a small piece of land原创 2017-11-06 20:24:27 · 356 阅读 · 0 评论 -
03-树3 Tree Traversals Again(25 分)
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stac原创 2017-10-11 21:08:14 · 241 阅读 · 0 评论 -
List Leaves
03-树2 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 e原创 2017-09-24 16:34:41 · 223 阅读 · 0 评论 -
二叉树(2)
#include#includeusing namespace std;#include#include #define error -1//#define scanf scanf_stypedef int ElementType;//假定节点数据为整数 #define NoInfo 0//用0表示没有节点 typedef struct TNode *Posit原创 2017-04-08 13:36:46 · 254 阅读 · 0 评论 -
二叉搜索树的插入和删除
//************************************************************************************************二叉树搜索树的插入要点: 1.分为二叉搜索树是否为空两种情况 2.用递归的方法BinTree Insert(BinTree BT, int X){ if原创 2017-04-08 17:04:55 · 222 阅读 · 0 评论 -
C语言快速排序函数qsort
快速排序库函数qsort的函数原型 void qsort(void *a,int nelem,unsigned int width,int(*pfCompare)(const void* e1,const void* e2));依次是 要排序数组的首地址 元素个数 元素的字节 比较的函数#includeint Compare(const void* e1,原创 2017-04-09 20:25:16 · 366 阅读 · 0 评论 -
平衡二叉树的创建过程
#include#includetypedef struct AVLNode* Position;typedef Position AVLTree;//AVL树类型struct AVLNode {int Data;//节点数据AVLTree Left;//指向左子树AVLTree Right;//指向右子树int Height;//树高 };int Max(原创 2017-04-15 16:16:04 · 1671 阅读 · 0 评论 -
树的应用——最大堆的建立
#include#includetypedef struct HNode *Heap;//堆的定义类型 struct HNode{int* Data;//存储元素的数组int Size;//堆中当前元素的个数 int Capacity;//堆的最大容量 };typedef Heap MaxHeap;void Print(MaxHeap H);void Per原创 2017-04-15 19:31:33 · 374 阅读 · 0 评论 -
最大堆的插入和删除
//********************************************************************最大堆的插入int IsFull(MaxHeap H){return H->Capacity == H->Size;}int Insert(MaxHeap H, int X){//将元素X插入最大堆H,其中H->Data[0]已经定原创 2017-04-15 23:53:18 · 290 阅读 · 0 评论 -
图的储存之邻接矩阵
#include#include#includeusing namespace std;#define MaxVertexNum 100 //最大顶点数设为100 #define INFINTY 65535 typedef int Vertex; //用顶点下标表示顶点,为整形typedef int WeightType; //边的权值设为整数ty原创 2017-05-03 20:34:29 · 206 阅读 · 0 评论 -
图的储存之邻接表
#include#include#includeusing namespace std;#define MaxVertexNum 100 //最大顶点数为100typedef int Vertex; //用顶点下标表示顶点,为整型 typedef int WeightType; //边的权值设为整型 typedef char DataType原创 2017-05-03 20:35:20 · 187 阅读 · 0 评论 -
归并排序的递归实现
const int maxn = 100;//将数组A的[L1,R1]与[L2,R2]区间合并为有序区间(此处L2即为R1+1)//归并排序的递归实现void merge(int A[], int L1, int R1, int L2, int R2){ int i = L1, j = L2; int temp[maxn], index = 0;//临时存放合并后的数组,index为其原创 2017-11-21 21:40:45 · 190 阅读 · 0 评论