随笔分类 - 数据结构
摘要:一、介绍 哈希表是根据关键字(Key)而直接访问记录的数据结构。它通过把关键字映射到哈希表中的一个位置来访问记录,以加快查找的速度。这个映射函数叫做散列函数,存放记录的数组叫做哈希表。 散列函数:将记录的关键字映射到该记录在哈希表中的存储位置,即f(关键字) = 记录的存储位置 示例:以查新华字典为
阅读全文
摘要:prim:逐“点”生成最小生成树 与Dijkstra不同的是:加入点到生成树中,不要考虑与源点的距离,而是考虑与生成树的距离
阅读全文
摘要:时间复杂度:O(n3) 测试及结果:
阅读全文
摘要:简易之处:顶点无序号,只能默认手动输入0,1,2...(没有灵活性) 测试方法及结果:
阅读全文
摘要:#include #include #include #include #include #include using namespace std; const int VERTEX_NUM = 20; const int INFINITY = 0x7fffffff; // 最大int型数,表示权的无限值 bool vis[VERTEX_NUM]; class Grap...
阅读全文
摘要:递归 + 标记 一个连通图只要DFS一次,即可打印所有的点。
阅读全文
摘要:邻接表 + 逆邻接表 = 十字链表 (十字链表把邻接表和逆邻接表整合在一起) 邻接表:计算出度容易,但计算入度就需要遍历全图,故衍生了十字链表。
阅读全文
摘要:#include #include using namespace std; const int VERTEX_NUM = 20; const int INFINITY = 0x7fffffff; // 最大int型数,表示权的无限值 class Graph { public: int vexNum; int edgeNum; int vex[VERTEX_NUM]; i...
阅读全文
摘要:#include #include #include using namespace std; using ElemType = int; // 队列结点 class Node { public: ElemType data; Node *next; }; class Queue { public: Node *front; Node *rear; }; void in...
阅读全文
摘要:【补充】 循环队列队首和队尾的一些关系(假设队首下标为front,队尾下标为rear,数组长度为MAXSIZE): 队列为空:rear == front 队列为满:(rear + 1) % MAXSIZE == front //(基于给队列留一个空闲位置而实现,不然和队列为空时条件重合) 队列长度:
阅读全文
摘要:#include #include #include #include using namespace std; using ElemType = int; // 堆栈结构 class Node { public: ElemType data; Node *next; }; // 初始化栈 Node* initStack(Node *head, int n) { sr...
阅读全文
摘要:#include #include #include #include using namespace std; using ElemType = int; const int MAXSIZE = 20; // 堆栈结构 class Stack { public: ElemType data[MAXSIZE]; int top; }; // 初始化堆栈 void ini...
阅读全文
摘要:#include #include #include #include using namespace std; using ElemType = int; // 双向链表结点 class Node { public: ElemType data; Node *next; Node *prior; }; // 初始化链表 void initList(Node *h...
阅读全文
摘要:#include #include #include using namespace std; using ElemType = int; // 单链表结构 class Node { public: ElemType data; Node *next; }; // 初始化单链表 void initList(Node *head) { char ch; int val...
阅读全文
摘要:#include #include #include using namespace std; const int MAXSIZE = 20; using ElemType = int; // 线性表结构 class SqList { public: ElemType data[MAXSIZE]; int length; }; // 创建线性表list SqList cr...
阅读全文