#在开始写博客之前,题主非常感谢现在大三遇到的算法老师,大一大二年少无知,自我感觉浪费了很多的时间大三遇到了更优秀的人、更优秀的老师、搬到了更加优秀的校区,才知道,其实,题主的敌人就只有一个,那就是自己。
(一百年的毒鸡汤,废话不多说,因为我还有很多作业没有写。。。。)
*编译器 vs2013
*语言 C++
(ps:使用邻接矩阵存储有向图)
求解最短路径的一个示例
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <map>
#define random(a,b) (rand()%(b-a+1)+a)
//用来生成随机数的函数
using namespace std;
//create a paragraph with 100 nodes and 3000 edges
typedef struct Node{
int vertex;
int weight;
Node * next;
};
static int MAX_SIZE = 10000000;
static int VC = 100;
struct Node * HeadNode;
map<int, Node*> Heads;
map<int, int> store_stack;
int vertex_size=0;
bool marked[101];
int dis[101];
int previous[101];
//所有的存储都从1开始
//initialization count vertex head pointer and store it in the Heads
//这里的count,指的是要随机生成的节点的数目
void initLinks(int count){
for (int i = 1; i <= count; i++){
Node* head = new Node;
head->vertex = i;
head->weight = 0;
head->next = NULL;
Heads[i] = head;
}
vertex_size = count;
}
//create a new node and insert into the link of corresponding