4、数据结构
数据结构
Estrellas_
I am the king of the world.
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
pat a1034 团伙头目【图的深搜】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805456881434624一、问题描述One way that the police finds the head of a gang is to check people's phone calls. If there is a phone ca...原创 2020-01-22 20:37:08 · 363 阅读 · 0 评论 -
图的深搜
通用模板(思路)DFS(u){ visit[u]=true; for(从u出发所能到达的所有顶点v) { if visit[v]==false DFS(v) }}DFSTrave(G){ for(G的所有顶点u) if visit[u]==false DFS(u); }const int maxv=1000;const int inf=100...原创 2020-01-22 19:29:23 · 367 阅读 · 0 评论 -
codeup 21142: 合并果子【哈夫曼树】
一、题目描述在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆。多多决定把所有的果子合成一堆。每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之和。可以看出,所有的果子经过n-1次合并之后,就只剩下一堆了。多多在合并果子时总共消耗的体力等于每次合并所耗体力之和。因为还要花大力气把这些果子搬回家,所以多多在合并果子时要尽可能地节省体力...原创 2020-01-22 14:07:22 · 285 阅读 · 0 评论 -
堆的基本操作
const int maxn=100;int heap[maxn]; //堆 int n=10; //元素个数 1、向下调整对heap数组在【low,high】范围进行向下调整其中low为欲调整结点的数组下标,high一般为堆的最后一个元素的数组下标//对heap数组在【low,high】范围进行向下调整 //其中low为欲调整结点的数组下标,high一般为堆...原创 2020-01-21 22:01:58 · 430 阅读 · 0 评论 -
好朋友【并查集】
一、问题描述 有一个叫做“数码世界”奇异空间,在数码世界里生活着许许多多的数码宝贝,其中有些数码宝贝之间可能是好朋友,并且数码宝贝世界有两条不成文的规定: 第一,数码宝贝A和数码宝贝B是好朋友等价于数码宝贝B与数码宝贝A是好朋友 第二,如果数码宝贝A和数码宝贝C是好朋友,而数码宝贝B和数码宝贝C也是好朋友,那么A和B也是好朋友,现在给出这些数码宝...原创 2020-01-21 20:18:53 · 470 阅读 · 0 评论 -
并查集的基本操作
1、初始化for(int i=1,i<=N;i++) { father[i]=i;} 2、查找int findFather(int x) { while(x!=father[x]) { x=father[x]; } return x;}递归版本:int findFather(int x) //递归版本 { if(x==father[x...原创 2020-01-21 18:08:06 · 368 阅读 · 0 评论 -
平衡二叉树的基本操作
1、结点数据结构定义struct Node{ int v; int height; Node* lchild; Node* rchild;};2、新建结点Node* newNode(int v){ Node* node=new Node; node->v=v; node->height=1; node->lchild=node->rch...原创 2020-01-21 16:14:05 · 328 阅读 · 0 评论 -
pat a1043 二叉排序树 镜像树
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805440976633856https://www.nowcoder.com/pat/5/submission-detail/64125906一、题目描述PAT a1043Is It a Binary Search Tree(25分)A ...原创 2020-01-20 23:18:02 · 377 阅读 · 0 评论 -
二叉查找树的基本操作
1、查找void search(Node* root,int x){ if(root==NULL) { printf("search failed\n"); return; } if(x==root->data) { printf("%d\n",root->data); } else if(x<root->data) { sear...原创 2020-01-20 21:24:04 · 239 阅读 · 0 评论 -
pat a1053 给定权值和,求路径
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805424153280512https://www.nowcoder.com/pat/5/submission-detail/641140481053Path of Equal Weight(30分)Given a non-empty tree...原创 2020-01-20 17:51:49 · 398 阅读 · 0 评论 -
树的遍历
1、树的先根遍历//树的先根遍历 void preOrder(int root) { printf("%d",node[root].data); for(int i=0;i<node[root].child.size();i++) { preOrder(node[root].child[i]); }}2、树的层序遍历//树的层序遍历void LayerO...原创 2020-01-19 21:24:38 · 211 阅读 · 0 评论 -
pat a1020 后序+中序,建树,并求层序序列
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805485033603072给出一棵二叉树的后序遍历序列和中序遍历序列,求这棵二叉树的层序遍历序列。#include<cstdio>#include<cstring>#include<queue>#incl...原创 2020-01-19 20:21:01 · 299 阅读 · 0 评论 -
根据先序、中序序列,重建二叉树
给定一棵二叉树的先序遍历序列和中序遍历序列,重建这棵二叉树。//当前先序序列区间为【preL,preR】//当前中序序列区间为【inL,inR】//返回根结点地址Node* create(int preL,int preR,int inL,int inR){ if(preL>preR) return NULL; Node* root=new Node; root...原创 2020-01-19 19:55:09 · 330 阅读 · 0 评论 -
二叉树的遍历
1、先序遍历void preorder(Node* root){ if(root==NULL) return; printf("%d\n",root->data); preorder(root->lchild); preorder(root->rchild);}2、中序遍历void inorder(Node* root){ if(root==NUL...原创 2020-01-19 17:22:15 · 166 阅读 · 0 评论 -
二叉树的基本操作
一、结点的数据结构定义struct Node{ int data; Node* lchild; Node* rchild;};二、新建一个结点Node* newNode(int v){ Node* node=new Node; node->data=v; node->lchild=NULL; node->rchild=NULL; return...原创 2020-01-18 17:27:07 · 240 阅读 · 0 评论 -
pat a1052 Linked List Sorting ------ 静态链表排序
题目:https://www.nowcoder.com/pat/5/problem/4091https://pintia.cn/problem-sets/994805342720868352/problems/994805425780670464A linked list consists of a series of structures, which are not neces...原创 2020-01-16 23:34:33 · 198 阅读 · 0 评论 -
pat a1032 Sharing ------共有后缀
To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example,...原创 2020-01-16 14:02:46 · 209 阅读 · 0 评论 -
单链表的基本操作
1、创建#include<iostream>using namespace std;struct node{ int data; node* next;};node* create(int array[],int n){ node* head=new node; head->next=NULL; //别忘记置空!! node* pre=head;...原创 2020-01-15 20:50:30 · 221 阅读 · 0 评论 -
codeup 1918: 简单计算器
题目:http://codeup.cn/problem.php?id=1918题目描述读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值。输入测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔。没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出。输出对每个测试用例输出1行,即该表达式的...原创 2020-01-15 00:34:18 · 276 阅读 · 0 评论 -
堆排序
堆排序 核心思想: 前提知识:堆其实就是一种特殊的完全二叉树,分为大顶堆和小顶堆,大顶堆就是指父节点>=左右孩子结点,而左右孩子结点之间的大小关系随意,小顶堆反之 堆排序核心:就是先把序列构建成大顶堆序(升序用大顶堆),然后大顶堆的根节点和最后一个结点交换位置,这样一来每交换一次就得到当前序列的最大值,并把它放在了最后面,接着把剩下的序列继续构建成大顶堆,重复上面动作,直到序列...转载 2019-03-12 20:17:51 · 182 阅读 · 0 评论
分享