题目 用链表实现栈 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <malloc.h> #include<assert.h> typedef struct Stack { int nValue; struct Stack *pNext; }Stack, *PStack; PStack CreateStack() { PStack pSta…
 题目 用数组实现栈 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <malloc.h> #include<assert.h> typedef struct Stack { int nTop; int nLen; int *pnArr; }Stack, *PStack; //初始化栈 nLen为栈的大小 PStack Create(int…
 题目 最短路径 解决代码及点评 // 26最短路径dijstra.cpp : 定义控制台应用程序的入口点. // #include <iostream> using namespace std; const int N=1000; /* 单源最短路径:Dijkstra算法 算法思想: 从源点开始,每次合并距离源点所在集合最近的点到源点集合,距离用dis[]记录, 合并之后应用松弛原理更新dis[]的值.直到所有的点均在源点集合,或者发现了图不连通. 应用范围: 有向图,边的权值非负.…
 题目 基于数组的队列 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <malloc.h> #include<assert.h> #define N 10 typedef struct Queue { int nHead; int nTail; int nLen; int *pnArr; }Queue, *PQueue; PQueue Cr…
 题目 基于链表的队列实现 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <malloc.h> #include<assert.h> typedef struct QNode { int nValue; struct QNode *pNext; }QNode, *PQNode; typedef struct { PQNode pHead;…
 题目 拓扑排序 解决代码及点评 // 拓扑排序.cpp : 定义控制台应用程序的入口点. // // 深度优先.cpp : 定义控制台应用程序的入口点. // // 图的邻接表表示.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <stack> #include <queue> #include <array> using namespace std; template<class T&…
 题目 图的邻接矩阵表示 解决代码及点评 // 图的邻接矩阵表示.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <list> using namespace std; #define MAXVEX 10 #define INFINITY 65535 typedef struct { char vexs[MAXVEX]; int arc[MAXVEX][MAXVEX]; int numVertexes; int num…
 题目 图的邻接表表示 解决代码及点评 // 图的邻接表表示.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <stack> using namespace std; template<class T> class EdgeNode { public: T adjvex; EdgeNode *pnext; }; template<class T> class Graph { public: Gr…
 题目 深度优先 解决代码及点评 // 深度优先.cpp : 定义控制台应用程序的入口点. // // 图的邻接表表示.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <stack> #include <queue> #include <array> using namespace std; template<class T> class EdgeNode { public: T a…
 题目 区间树 解决代码及点评 #include <stdio.h> #include <string.h> #include <iostream> #define MAX(x,y) ((x)>(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y)) #define NL 262144 struct Seg { int l, r; int w; }t[NL*2]; int h, w, row; void build…