基于Dijkstra算法的路径导航

该博客介绍了一种使用Dijkstra算法在有向或无向图中寻找最短路径的方法。首先,定义了数据结构和图类型,接着通过用户输入构建图,并利用Dijkstra算法找出起点到终点的最短路径。代码示例展示了算法的具体实现。
摘要由CSDN通过智能技术生成
/***************************************************
文件名:路线导航
创建人:张劲暾
创建日期:20171204
****************************************************/
#include <iostream>
#include <cstring>
#include <cstdlib>
#define MapSize 256         //邻接矩阵大小
#define ArcMax 30000       //边权值最大值
#define OK 1
#define ERROR 0
using namespace std;
typedef int Status;
typedef enum{DN,UDN}GraphKind;  //DN——有向网,UDN——无向网
typedef struct StackNode{
    int num;
    StackNode* next;
}StackNode,*Stack;
typedef struct Way{
    int last_one;
    float dist;
}Way;
typedef struct ArcCell{     //边类型:ArcCell,AdjMatrix[MapSize][MapSize];
    float   power;    //边的权值
}ArcCell,AdjMatrix[MapSize][MapSize];
typedef struct MGraph{  //图类型:MGraph;
    char vex[MapSize][25];   //顶点向量
    AdjMatrix arcs;         //邻接矩阵
    int vexnum,arcnum;    //边数和顶数
    GraphKind kind;
}MGraph;
Status InitStack(Stack &S){
    S = (Stack)malloc(sizeof(StackNode));
    S->next = NULL;
    S->num = -1;
    return OK;
}//InitStack
Status Push(Stack &S,int n){
    Stack tmp = S,in;
    while(tmp->next) tmp = tmp->next;
    in = (Stack)malloc(sizeof(StackNode));
    in->next = NULL;
    in->num = n;
    tmp->next = in;
    return OK;
}//Push
Status Pop(Stack &S,int &n){
    if(S->next ==
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值