山东大学算法设计与分析实验1----创建有向图并且求出某点到各个点的最短距离

#在开始写博客之前,题主非常感谢现在大三遇到的算法老师,大一大二年少无知,自我感觉浪费了很多的时间大三遇到了更优秀的人、更优秀的老师、搬到了更加优秀的校区,才知道,其实,题主的敌人就只有一个,那就是自己。
(一百年的毒鸡汤,废话不多说,因为我还有很多作业没有写。。。。)
*编译器 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 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值