基础算法
Sanalar
这个作者很懒,什么都没留下…
展开
-
用链表实现队列
源代码:#includeusing namespace std;struct Node{ int n; Node * next;};Node * pTail = NULL;void enter(Node * &pHead, int x){ Node * pNew = new Node; pNew->n = x; pNew->next = NULL; if (!pHe原创 2015-10-06 15:25:26 · 297 阅读 · 0 评论 -
用链表实现栈功能
#includeusing namespace std;struct Node{ int n; Node * next;};void push(Node *&pHead, int x){ Node *pNew = new Node; pNew->n = x; pNew->next = NULL; if (!pHead) { pHead = pNew; } e原创 2015-10-06 14:14:27 · 442 阅读 · 0 评论 -
括号匹配问题
源程序如下#includeusing namespace std;struct Node{ char n; Node * next;};void push(Node *&pHead, char x){ Node *pNew = new Node; pNew->n = x; pNew->next = NULL; if (!pHead) { pHead = pN原创 2015-10-06 14:51:08 · 301 阅读 · 0 评论 -
并查集
路径压缩之后的算法最初的算法,在查找一个结点的根的时候,可能会遇到树枝很长的情况。路径压缩就是在寻找根的时候,顺便把这个结点的父节点改成最终要寻找的根。int pre[];int GetRoot(int a) { if(pre[a] != a) pre[a] = GetRoot(pre[a]); return par[a];}bool Query(int a,翻译 2017-03-01 20:34:51 · 185 阅读 · 0 评论 -
单源次短路径
// 单源最短路径问题的整理 // 需要的数据结构:map[i][j]用来存放点与点之间的权used[i]用来标记点是否已经被用过dist[i]用来动态记录从 起点到该点的最短距离// 具体的操作步骤// 1. 初始化各项内容 // 2. 在使用的点中找出已经求出的确定的最短路径,并标记为已使用 // 3. 根据已经确定的最短路径的点,更新其余的dist[i] #include<iost原创 2017-03-01 20:36:53 · 709 阅读 · 0 评论