数据结构
以强大回敬热爱
这个作者很懒,什么都没留下…
展开
-
图的几种应用
最小生成树 最短路径 拓扑排序 关键路径求解原创 2021-08-27 16:38:02 · 101 阅读 · 0 评论 -
图的两种遍历
深度优先搜索 广度优先搜索 1深度优先搜索 //算法6.3 深度优先搜索遍历连通图的递归算法 #include <iostream> using namespace std; #define MVNum 100 //最大顶点数 typedef char VerTexType; //假设顶点的数据类型为字符型 typedef int ArcType; //假设边的权值类型为整型 typedef struct{原创 2021-08-27 14:20:39 · 306 阅读 · 0 评论 -
图的存储结构
邻接矩阵 领接表 邻接矩阵 //算法6.1 采用邻接矩阵表示法创建无向网 #include <iostream> using namespace std; #define MaxInt 32767 //表示极大值,即∞ #define MVNum 100 //最大顶点数 #define OK 1 typedef char VerTexType; //假设顶点原创 2021-08-27 13:25:25 · 77 阅读 · 0 评论 -
哈夫曼树与哈夫曼编码
一、构造哈夫曼树 二、哈夫曼编码 构造哈夫曼树 哈夫曼树的存储: typedef struct { int weight;//结点的权值 int parent, lchild, rchild;//节点的双亲、左孩子、右孩子的下标 }HTNode,*HuffmanTree; 算法思想: 1.初始化HT[1,2…2n-1]:lchild=rchild=parent=0; 2.输入初始n个叶子结点:置HT[1, n]的weight值 3.进行n-1次合并,依次产生n-1个结点HT[i],i=n+1…,原创 2021-08-24 22:57:47 · 96 阅读 · 0 评论 -
LRU缓存机制的实现
LRU LRU缓存机制leetcode题 class LRUCache { typedef list<pair<int,int>> LRUlist; typedef list<pair<int,int>>::iterator LRU_LIST_IT; public: LRUCache(int capacity){ _capacity=capacity; } int get(int key)原创 2021-08-21 23:25:01 · 86 阅读 · 0 评论 -
二叉树的建立
二叉树的建立 例: 通过前序遍历的数组"ABD##E#H##CF##G##"构建二叉树 #include<stdio.h> #include<stdlib.h> typedef char DataType; typedef struct BNode { struct BNode* _left; struct BNode* _right; DataType _data; }Node; Node* creatBinaryTree(DataType arr[], int* idx)原创 2021-08-20 20:32:18 · 60 阅读 · 0 评论 -
前序遍历、中序遍历、后序遍历非递归遍历的实现思想
1.前序遍历:遍历最左路径,节点入栈,访问遍历的每一个节点,获取栈顶元素,栈顶元素出栈。接着访问栈顶元素右子树。 2.中序遍历:遍历最左路径,节点入栈但不访问。左路径访问完后,获取栈顶元素,栈顶元素出栈,访问栈顶元素。访问栈顶元素右子树。 3.后序遍历:遍历最左路径,节点入栈不访问,或取栈顶元素,判断栈顶元素有没有右子树,若没有右子树或者右子树已经访问了,则访问栈顶元素,否则访问栈顶元素。 来源青岛大学王卓 ...原创 2021-08-20 13:39:17 · 349 阅读 · 0 评论 -
二叉树的层次遍历
二叉树的层次遍历 算法思想: 1.将根节点入队 2.队列不为空,一直循环,从队列取出一个节点*p,访问 来源于青岛大学王卓 void bTreeLevelOrder(Node* root) { //借助队列保存节点 Queue q; initQueue(&q); if (root) { queuePush(&q,root); } while (!isEmpty()) { Node* front = queuefront(&q); queuePop(&原创 2021-08-20 13:21:08 · 78 阅读 · 0 评论 -
用队列实现栈
用队列实现栈 class MyStack { public: /** Initialize your data structure here. */ MyStack() { } /** Push element x onto stack. */ void push(int x) { q2.push(x); while(!q1.empty()) { q2.push(q1.front())原创 2021-08-19 10:40:09 · 51 阅读 · 0 评论 -
用栈实现队列
1.用栈实现队列 class MyQueue { public: /** Initialize your data structure here. */ MyQueue() { } /** Push element x to the back of queue. */ void push(int x) { s1.push(x); } /** Removes the element from in front of原创 2021-08-19 10:38:42 · 54 阅读 · 0 评论