#include "iostream"
#include "math.h"
#include "fstream"
#define MAX 5 //顶点个数
using namespace std;
typedef struct node
{
char number;//顶点按字母编码,存在flat里面
int weight_number[MAX][2];//到每个相邻顶点的距离
int flag;//标记
}NODE;
NODE node[MAX];//顶点集合
char NOde[MAX];//顶点编号读入的存储
char hash_char[MAX][MAX*2];
char road[MAX];//最短路径的存储
int R;
char temp;//记录最新加入到路径中的点
void file_in();
void close_to();
void zhuanhuan();
int min(char t);
int locate(char tt);
///////////////////////////////////////////////////////////////////////////////////////////
/*主函数*/
void main()
{
cout<<"说明:顶点编号必须是26个英文字母。数据存放在“data.txt”文件里面"<<endl;
cout<<" 第一行存放顶点编号。顶点之间的距离需要用空格隔开"<<endl<<endl;
cout<<" 例如:"<<endl;
cout<<" 12 23 2 4"<<endl;
file_in();//数据读入
close_to();//最邻近算法找最短路径
for(int i=0;i<MAX;i++)
cout<<road[i];
}
///////////////////////////////////////////////////////////////////////////////////////////
/*最短路函数*/
void close_to()
{
R=0;
int wh=0;
char first,last;
cout<<"起始顶点:";
cin>>first;
cout<<"终点:";
cin>>last;
road[R]=first;//最短路径的起始点
R++;
temp=first;
while(1)
{
if(node[wh].number==first)
{
node[wh].flag=1;
break;
}
}
min(temp);
}
///////////////////////////////////////////////////////////////////////////////////////////////