数据结构课程设计做的 要求是做自己学校的交通图
不知道程序的效率怎么样
请各位大神指点 小弟不胜感激
类型声明:
#ifndef STATEMENT_H_INCLUDED
#define STATEMENT_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXNUMVETEX 25
#define NotAVetex (-1)
#define MINWEIGHT (-1)
#define INFINITY 10000/*later ues math.h*/
#define LeftChild(i) (2*(i))
#define RightChild(i) (2*(i)+1)
#define Parent(i) ((i)/2)
#define GraphLEN sizeof(struct GraphAdjacencyList)
#define EdgeLEN sizeof(struct EdgeNode)
#define PriorityQueueLEN sizeof(struct Heap)
#define TableLEN sizeof(struct TableEntry)
#define VetexNodeLEN sizeof(struct VetexNode)
struct VetexNode;
struct EdgeNode;
struct AdjacencyListNode;
struct GraphAdjacencyList;
typedef struct EdgeNode *Edge;
typedef struct VetexNode AdjacencyList;
typedef struct GraphAdjacencyList *Graph;
typedef struct TableEntry Table;
typedef struct TableEntry *PtrToTable;
typedef struct Heap *PriorityQueue;
struct EdgeNode
{
int VetexId;
char Name[20];
double Dist;
double Time;
Edge Next;
};
struct VetexNode
{
int NumEdge;
int IsClassRoom;
int Id;
char Name[20];
Edge Header;
};
struct GraphAdjacencyList
{
int NumVetex,NumEdge;
AdjacencyList *AdList;
};
struct TableEntry
{
int Known;
int VetexId;
int Path;
double Dist;
double Time;
};
struct Heap
{
int Size;
int Capacity;
PtrToTable *Element;
};
#endif // STATEMENT_H_INCLUDED
导入地图的程序
#include "statement.h"
int FindVetexIdBaseName(char str[],Graph G)
{
int i;
for(i=0;i<G->NumVetex&&strcmp(str,G->AdList[i].Name)!=0;i++){}
return (i);
}
int IsChinese(char str[])
{
int i;
for(i=0;str[i]!='\0';i++)
{
if(str[i]>=0&&!(str[i]>='0'&&str[i]<='9'))
return 0;
}
return 1;
}
Graph CreatGraph(void)
{
int i,Cell1,Cell2;
double TmpDist,TmpTime;
Graph G;
char Tmpstr1[20],Tmpstr2[20];
Edge TmpEdge;
G=malloc(GraphLEN);
puts("input the Number of Vetex:");
scanf("%d",&G->NumVetex);
G->AdList=calloc(G->NumVetex,VetexNodeLEN);
puts("input the Number of Edge:");
scanf("%d",&G->NumEdge);
puts("Now Input The Vetex Information:");
puts("Every Place'Name Must Use Chinese Language Or Number!");
puts("");
for(i=0;i<G->NumVetex;i++)
{
G->AdList[i].NumEdge=0;
G->AdList[i].IsClassRoom=0;
G->AdList[i].Id=i;
do
{
printf("Input The No.%d Vetex's Name:",i+1);
scanf("%s",G->AdList[i].Name);
}while(!IsChinese(G->AdList[i].Name));
printf("Is This Vetex A ClassRoom?(1/0) :");
scanf("%d",&G->AdList[i].IsClassRoom);
TmpEdge=malloc(EdgeLEN);
TmpEdge->Next=NULL;
TmpEdge->Time=0;
TmpEdge->Dist=0;
strcpy(TmpEdge->Name,G->AdList[i].Name);
TmpEdge->VetexId=G->AdList[i].Id;
G->AdList[i].Header=TmpEdge;
TmpEdge=NULL;
}
puts("Now Input The Edge Information:");
puts("There Is Space Between Two Place's Name!");
puts("");
for(i=0;i<G->NumEdge;i++)
{
printf("No.%d Edge:Input Two Vetex's Name:",i+1);
scanf("%s %s",Tmpstr1,Tmpstr2);
Cell1=FindVetexIdBaseName(Tmpstr1,G);
if(strcmp(Tmpstr1,G->AdList[Cell1].Name)!=0)
{
puts("Not have this Vetex!,Input Again!");
i--;
continue;
}
Cell2=FindVetexIdBaseName(Tmpstr2,G);
if(strcmp(Tmpstr2,G->AdList[Cell2].Name)!=0)
{
puts("Not have this Vetex!,Input Again!");
i--;
continue;
}
G->AdList[Cell1].NumEdge++;G->AdList[Cell2].NumEdge++;
puts("Input the Distance Of Two Vetex:");
scanf("%lf",&TmpDist);
puts("Input the Time-Cost Of Two Vetex:");
scanf("%lf",&TmpTime);
TmpEdge=malloc(EdgeLEN);
TmpEdge->Dist=TmpDist;
TmpEdge->Time=TmpTime;
strcpy(TmpEdge->Name,G->AdList[Cell2].Name);
TmpEdge->VetexId=G->AdList[Cell2].Id;
TmpEdge->Next=G->AdList[Cell1].Header;
G->AdList[Cell1].Header=TmpEdge;/*Let Cell2 Vetex Linked Cell1 To Make A Edge*/
TmpEdge=malloc(EdgeLEN);
TmpEdge->Dist=TmpDist;
TmpEdge->Time=TmpTime;
strcpy(TmpEdge->Name,G->AdList[Cell1].Name);
TmpEdge->VetexId=G->AdList[Cell1].Id;
TmpEdge->Next=G->AdList[Cell2].Header;
G->AdList[Cell2].Header=TmpEdge;/*Let Cell1 Vetex Linked Cell1 To Make A Edge*/
}
return G;
}
void SaveGraph(Graph G)
{
int i;
FILE *fp;
Edge HeadEdge;
if((fp=fopen("Graph.dat","wb"))==NUL