| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 486 人关注过本帖
标题:图最短路径问题
取消只看楼主 加入收藏
雪花神剑
Rank: 2
来 自:吉林
等 级:论坛游民
帖 子:579
专家分:47
注 册:2009-3-12
结帖率:94.74%
收藏
已结贴  问题点数:20 回复次数:0 
图最短路径问题
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
const int MaxWeight=10000;
const int MaxGraphSize=256;                        //定义的顶点最多值
void Menu(void);
struct scenery
{
    char name[20];
    int num;
    char Introduction[200];
};
class   Graph_Matrix
{
private:
    int edge[MaxGraphSize][MaxGraphSize];
    int graphsize;                         //图中顶点个数。
    scenery sce[20];                     //景点
public:
    Graph_Matrix()
    {
        
        for(int i=0;i<10;i++)
        {
            sce[i].num=i;
        }
        strcpy(sce[0].name,"2");
        strcpy(sce[0].Introduction,"3");
        strcpy(sce[1].name,"4");
        strcpy(sce[1].Introduction,"5");
        strcpy(sce[2].name,"2");
        strcpy(sce[2].Introduction,"4");
        strcpy(sce[3].name,"5");
        strcpy(sce[3].Introduction,"3");
        strcpy(sce[4].name,"3");
        strcpy(sce[4].Introduction,"3");
        strcpy(sce[5].name,"3");
        strcpy(sce[5].Introduction,"3");
        strcpy(sce[6].name,"3");
        strcpy(sce[6].Introduction,"3");
        strcpy(sce[7].name,"3");
        strcpy(sce[7].Introduction,"3");
        strcpy(sce[8].name,"3");
        strcpy(sce[8].Introduction,"3
        strcpy(sce[9].name,"3");
        strcpy(sce[9].Introduction,"3");      
        graphsize=10;      
        for(int m=0;m<graphsize;m++)
            for(int n=0;n<graphsize;n++)
                edge[m][n]=MaxWeight;
            edge[0][1]=100;
            edge[0][2]=200;
            edge[0][6]=400;
            edge[1][7]=300;
            edge[2][3]=120;
            edge[3][6]=220;
            edge[3][4]=100;
            edge[4][5]=300;
            edge[4][9]=250;
            edge[5][9]=350;
            edge[6][7]=60;
            edge[6][9]=200;
            edge[7][8]=50;
            edge[8][9]=20;
            for(int m1=0;m1<graphsize;m1++)
                for(int n1=0;n1<graphsize;n1++)
                    edge[m1][n1]=edge[n1][m1];
    }
    void ShortestPath(void)
   
            printf("请输入出发点和目的地的编号:");

         //大家帮我补充下这个函数吧。谢谢了。输入出发点 和目的点 的编号 。输出最短路径,eg:a->b->c->d->e;

        

类我定义好了。就是最短路径的函数不会。











搜索更多相关主题的帖子: 路径 
2010-08-24 21:37
快速回复:图最短路径问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.075983 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved