随笔分类 -  考研算法笔试

摘要:原文链接:深搜(非递归)实现获取两点之间的路径 阅读全文
posted @ 2018-12-14 03:16 Johnny、 阅读(914) 评论(0) 推荐(0)
摘要:晚上看视频的时候一不小心把浏览器关了,所以丢失了原文链接... 阅读全文
posted @ 2018-12-13 10:41 Johnny、 阅读(1269) 评论(0) 推荐(0)
摘要:输入样例:给定图如下 在关于bfs的代码编写的时候发现了自己 ->操作符和 .操作符乱用,下面作出说明: 比如你有这个结构体: 那么使用如下: 也就是说你用结构体定义了一个实体,那么这个实体要引用他里面的成员,就用.操作符 如果你用结构体定义的是一个结构指针,那么要引用他里面的成员就用-> 结合上述 阅读全文
posted @ 2018-12-12 02:17 Johnny、 阅读(4894) 评论(0) 推荐(1)
摘要:参考博客:图的深度优先遍历(递归、非递归;邻接表,邻接矩阵) 本代码有个问题:就是结点是对应存储下标的,要解决这个问题,可以增加一个定位函数(LocateVec),不修改也可以使代码简洁些 关于非连通图的bug已修改,就是增加了dfsTraverse函数循环遍历一遍结点:没访问过则再做一次dfs 样 阅读全文
posted @ 2018-12-11 15:48 Johnny、 阅读(12521) 评论(0) 推荐(1)
摘要:参考博客:图的深度优先遍历(递归、非递归;邻接表,邻接矩阵) 本篇默认连通图,非连通情况会在邻接表处补上 1.邻接矩阵的递归解法 2.邻接矩阵的非递归解法 基本思想: 初始化栈 输出起始顶点,起始顶点改为“已访问”标志,将起始顶点进栈 重复以下操作直至栈空: 去栈顶元素顶点,找到未被访问的邻接结点W 阅读全文
posted @ 2018-12-11 01:36 Johnny、 阅读(7685) 评论(0) 推荐(0)
摘要:原文链接:C语言邻接表的实现 这篇博文的代码写的很好,我就直接合并在一起贴出来了,方便自己使用,至于文章内容有需要可以看上述原文 阅读全文
posted @ 2018-12-09 02:31 Johnny、 阅读(322) 评论(0) 推荐(0)
摘要:1.邻接矩阵 2.邻接表 3.十字链表(有向图) 4.邻接多重表(无向图) 阅读全文
posted @ 2018-12-08 17:24 Johnny、 阅读(236) 评论(0) 推荐(0)
摘要:#include //向下调整 void HeapAdjust(int A[], int low, int high){ int i, temp = A[low]; for(i = low * 2; i 0; i--) HeapAdjust(A, i, n); //将最大值放至数组末端 for(i = n-1; i > 0; i--){ ... 阅读全文
posted @ 2018-12-04 00:11 Johnny、 阅读(204) 评论(0) 推荐(1)
摘要:#includeint Partition(int A[], int low, int high){ int pivot; pivot = A[low]; while(low = pivot)// 1.相等不替换 2.不要遗漏low < high的判断 high--; A[low] = A[high]; whil... 阅读全文
posted @ 2018-12-03 13:47 Johnny、 阅读(518) 评论(0) 推荐(0)
摘要:#include #include #include #define N 50 using namespace std; typedef struct tree{ char ch; struct tree *lchild; struct tree *rchild; }BitTree; //数组输入 BitTree *CreateTree(int A[], int ... 阅读全文
posted @ 2018-12-02 02:09 Johnny、 阅读(2229) 评论(0) 推荐(0)
摘要:#include #include #include #define N 50 using namespace std; typedef struct tree{ char ch; struct tree *lchild; struct tree *rchild; }BitTree; //数组输入 BitTree *CreateTree(int A[], int... 阅读全文
posted @ 2018-12-01 12:12 Johnny、 阅读(3043) 评论(0) 推荐(0)
摘要:#include #include #include #define N 50 using namespace std; typedef struct tree{ char ch; struct tree *lchild; struct tree *rchild; }BitTree; //键盘输入 BitTree *CreateTree(){ BitTre... 阅读全文
posted @ 2018-12-01 00:32 Johnny、 阅读(411) 评论(0) 推荐(0)
摘要:参考博客:C语言实现二叉树的非递归遍历 (内含思想) 引用了参考博客的模板,替换了中序和后序遍历的函数,三个函数用了三种栈实现方法 由于是自己编写的,感觉比较繁琐(不适合笔试书写),底部给出了更简洁的版本 测试结果: 简洁版本: 阅读全文
posted @ 2018-11-28 14:19 Johnny、 阅读(2062) 评论(0) 推荐(0)