
一些基础数据结构内容
文章平均质量分 72
渊渊大魔王
这个作者很懒,什么都没留下…
展开
-
题目1123:采药
十分典型的0 1背包问题,用动态规划思想进行解答,然而动态规划对数学不好的人来说是要命的,比如我这样的智障#include #include using namespace std;int max(int a,int b){ if (a > b) return a; else return b;}int main(){ int t,m; wh原创 2017-03-19 13:15:27 · 269 阅读 · 0 评论 -
题目1029:魔咒词典
不涉及算法,正确的输入和存储数据,然后进行查找即可。#include #include #include #include using namespace std;struct Item{ string word; string func;};int main(){ string s; int count; vector str;原创 2017-03-19 16:44:00 · 457 阅读 · 0 评论 -
图的最短路径算法
Dijstra:求单源最短路径,也就是某个点到其他所有点的最短路径#include #include using namespace std;struct Node //邻接链表中用来存放链表元素的结构体{ int next; int cost;};vector edge[101]; //二维数组,用邻接链表来存放边原创 2017-03-20 14:19:11 · 760 阅读 · 0 评论 -
题目1078:二叉树遍历
此题涉及到二叉树的遍历以及二叉树的建立#include #include using namespace std;struct Node //定义树的结点{ Node *lchild; Node *rchild; char c;};Node Tree[50]; //结点数组string str1,str2;voi原创 2017-03-20 16:59:46 · 254 阅读 · 0 评论 -
前缀、中缀、后缀表达式归纳
后缀表达式求值:后缀表达式是无需进行处理可以直接被计算机处理的表达式,运算符通常位于操作数的后面,例如: 3 4 + 5 * 6 - ,它是由中缀表达式(3 + 4) × 5 - 6转换过来的后缀表达式进行求值时,设立一个栈s1,从左到右依次访问表达式中的元素,如果遇到数字直接压入栈中,如果遇到运算符就将栈中最上方的两个元素取出后进行相应的运算,将运算结果压入栈中。具体c++代码如下:原创 2017-03-18 11:21:32 · 5054 阅读 · 0 评论 -
根据中序和后序遍历序列求层序遍历序列
如题,顺便还求了一下树的高度。#include #include #include using namespace std;struct Node{ Node *lchild; Node *rchild; char c;};void preOrder(Node *T){ cout c; if (T->lchild != NULL)原创 2017-03-23 17:30:43 · 1102 阅读 · 0 评论