![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
Rancho__
这个作者很懒,什么都没留下…
展开
-
二叉树的基本操作
二叉树的基本操作主要是输入的时候,对于一个叶子节点,它同样也是根节点,所以我们要输入两个空字符,代码中是以#代替的。还有就是广义表建立二叉树的时候,我们要让每次循环的P指针先指向处理后的根节点,然后进而让根节点入栈,此时用栈模拟先序建立,因为入栈出栈的过程就像dfs。#include <iostream>#include <cstdio>#include &l...原创 2018-12-07 20:20:31 · 156 阅读 · 0 评论 -
稀疏矩阵的基本操作
这是简版的,原版的一时半会找不到了。中文的很容易乱码,我们直接用英文好了。#include <iostream>#include <algorithm>#include <stdlib.h>#include <time.h>#include <cmath>#include <iomanip>#define...原创 2018-12-25 10:28:29 · 463 阅读 · 0 评论 -
图的遍历
图的遍历,对于dfs我们在主函数里面判断是否还有未遍历的点,然后dfs搜索,如果是旧点,我门就返回,如果不是我们就标记已搜,然后搜索这个点的邻接点。这样做的好处就是可以遍历非连通的图,因为我们一个dfs结束的时候可能不能遍历所有的点,所以我们直接判断是否还有新点即可。对于bfs也是一样,首先将队列置空,做初始化,然后搜索即可。#include <iostream>#in...原创 2018-12-28 10:38:19 · 119 阅读 · 0 评论 -
栈的基本操作
#include <iostream>#include <stdlib.h>using namespace std;const int INIT_SIZE=100;const int INCREASE=10;struct SqStack { int *base; int *top; int stacksize;};int InitStack(SqSta...原创 2018-11-05 21:57:00 · 109 阅读 · 0 评论 -
栈的表达式求值---通过运算符的优先级比较
#include <iostream>#include <stdlib.h>using namespace std;struct SqStack { char *base; char *top;};int cmp[10][10] = { {'>','>','<','<','<','>','>'},//+ {'&g...原创 2018-11-05 21:58:37 · 5471 阅读 · 0 评论 -
串的基本操作(KMP算法实现)
#include <iostream>#include <math.h>using namespace std;void StrAssign(char *T){ char ch; int i=1; cout<<"Please enter a string.0 is exit."<<endl; while (cin>>c...原创 2018-11-05 22:01:16 · 442 阅读 · 0 评论 -
链表的基本操作
#include <iostream>#include <math.h>using namespace std;void StrAssign(char *T){ char ch; int i=1; cout<<"Please enter a string.0 is exit."<<endl; while (cin>>c...原创 2018-11-05 22:02:36 · 70 阅读 · 0 评论 -
数组的基本操作
#include <iostream>#include <stdlib.h>using namespace std;struct SqList { int *elem; int length;};int InitList(SqList &L,int num){ L.elem = new int[num]; if (!L...原创 2018-11-05 22:04:04 · 163 阅读 · 0 评论 -
循环线性队列的基本操作(带实验数据)
#include <iostream>#include <cstring>using namespace std;bool overflow=0;struct Queue { int date[300]; int head; int tail; int len;}queue;void InitQueue(Queue &Q){ Q.hea...原创 2018-11-05 22:09:47 · 171 阅读 · 0 评论 -
数组的底层实现
#include <iostream>#include <stdlib.h>#include <string.h>#define max 8#define Elemtype intusing namespace std;typedef struct { Elemtype *base; int *bounds; int dim;//数组维数 ...原创 2018-11-11 11:34:00 · 2109 阅读 · 0 评论 -
Openjudge-2694-逆波兰表达式
这是波兰表达式,题目中叫它是逆波兰式。这个题的话,我们用递归求解,首先理解一下波兰表达式,就是将运算符前移了。像是二叉树的遍历一样,前序遍历就是波兰式,中序遍历就是中缀表达式,后序遍历就是逆波兰表达式。我们读入一项之后就进行处理,这里的读入因为题目中给出了空格,也就是一次读入的结束,所以我们每次读入的都是分隔的字符,浮点数的字符也是被分隔的,所以我们就可以直接使用atof函数将字符转浮...原创 2018-12-05 18:51:04 · 246 阅读 · 0 评论 -
最优二叉树(哈夫曼编码)
我们做一个放二叉树的结构体数组,数组里面读入的时候,我们只读入值,然后将二叉树的左右子树置为空。然后构造最优二叉树的过程就是,每次从二叉树数组中选取权值最小的二叉树,然后将这两个二叉树作为左子树和右子树,构造一个新的二叉树,双亲结点的权值就是它俩的权值之和。我们递归执行这一过程,当二叉树数组里面只剩下一颗二叉树的时候,递归结束,此时最优二叉树已经构建完毕,这时的父节点就是根节点。我们因...原创 2018-12-19 18:01:01 · 1053 阅读 · 0 评论 -
National Contest for Private Universities (NCPU), 2019 C Boxes(双向链表)
题目中的要求如果x在y的左边,不需要移动,x在y的右边,2操作不需要移动。有一个问题是,如果x与y相邻,这时的swap操作变成了三个而不是四个,这点尤其需要注意,不然就会死循环。注意x是和y相邻,这时应该考虑x在y的左边还是在y的右边,因为修改指针的操作是有方向性的。#include <bits/stdc++.h>using namespace std;const int ma...原创 2019-09-23 11:09:04 · 468 阅读 · 0 评论