摘要:#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;const int VERTEX_NUM = 7;const int INF = 0x7fffffff;struct V_UArc { int adjvex; int lowcost; // V中的顶点的lowcost为0以作标记}closedge[VERTEX_NUM + 1]; // 记录从顶点集U到V-U的代价最小的边的辅助数组定义int Minimum(V_UArc closedge[VERTEX_NUM + 1...
阅读全文
摘要:#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <queue>using namespace std;#define VERTEX_NUM 8bool visited[VERTEX_NUM + 1]; // 访问标志数组(备忘表)int FirstAdjVex(bool G[VERTEX_NUM + 1][VERTEX_NUM + 1], int v){ for (int j = 1; j <= VERTEX_NUM; j++) { if (G[v][j] == 1) ...
阅读全文
摘要:纯C:#include <stdio.h>#include <stdlib.h>#include <string.h>#define VERTEX_NUM 8typedef enum {FALSE = 0, TRUE = 1}BOOL;typedef struct ArcNode { int adjvex; struct ArcNode *nextarc; // struct不能少}ArcNode;BOOL visited[VERTEX_NUM + 1]; // 访问标志数组(备忘表)int FirstAdjVex(ArcNode *G[VERTEX_NUM
阅读全文
摘要:#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;#define PATH#define VERTEX_NUM 8#ifdef PATHint count = 1;#endifbool visited[VERTEX_NUM + 1]; // 访问标志数组(备忘表)struct ArcNode { int adjvex; ArcNode *nextarc;};int FirstAdjVex(ArcNode *G[VERTEX_NUM + 1], int v){ if ...
阅读全文
摘要:#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;//#define PATH#define VERTEX_NUM 8#ifdef PATHint count = 1;#endifbool visited[VERTEX_NUM + 1]; // 访问标志数组(备忘表)int FirstAdjVex(bool G[VERTEX_NUM + 1][VERTEX_NUM + 1], int v){ for (int j = 1; j <= VERTEX_NUM; j++) { ...
阅读全文
摘要:快速排序(递归):#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;#define LEN 8 // 有LEN个元素要排#define TESTstruct Record { // 为了考察排序的稳定性,定义元素是结构体类型 int key; int otherinfo;};int Partition(Record *arr, int low, int high){ // 交换顺序表L中子序列arr[low..high]的记录,使枢轴记录到位, // 并返回...
阅读全文
摘要:今天开了博客园的博客,纪念一下。我是大二的学生,下半年就大三了,很快。这学期的数据库上的真是难受,不过数据结构这门课我很喜欢,学了C,练了些程序,上这课感觉轻松些,学了许多算法,都是牛人想出来的啊,第一个是高德纳的KMP,后来有哈夫曼,Prim,Kruskal,还有荷兰的那位计算机科学家,他的最短路径算法出的还挺晚的。站在巨人的肩膀上学个不停,挺爽,我总是在想,我能不能想出这些算法,像哈夫曼树,感觉道理挺简洁的啊,我还想过,如果把二分查找、哈夫曼树的算法跟我做农的父母亲讲,我想他们一定都能听懂大概的做法,是个人都会二分。上排序那章时,我总是在想,我一定要设计一个O(log(n!))的算法,..
阅读全文