资源简介
数据结构图的知识,校园导游图,
可以查询所有路径和最短路径,自己写的算法。

代码片段和文件信息
#include “stdio.h“
#include “stdlib.h“
#include “string.h“
#define Max 20
struct Path
{int Pathway[Max][Max];
int Pathlength[Max];
int length;
};
struct Stack
{int a[Max];
int top;
};
struct ArcNode
{int adjvex;
int length;
ArcNode *nextarc;
};
struct VNode
{
char name[20];
char info[100];
ArcNode *firstarc;
};
struct Graph
{VNode vertices[Max];
int vexnumarcnum;
};
void InitGraph(Graph &g)
{g.vexnum=0;
g.arcnum=0;
}
void InitStack(Stack &S)
{S.top=0;}
void Push(Stack &Sint x)
{S.a[S.top]=x;
S.top++;
}
void GetTop(Stack &Sint &x)
{x=S.a[S.top-1];
}
bool Pop(Stack &Sint &x)
{if(S.top<0)
return 0;
else
{x=S.a[--S.top];
return 1;
}}
bool InStack(Stack Sint x)
{for (int i=0;i {if (S.a[i]==x)
{return 1;
}
}
return 0;
}
bool LocateVex(Graph gchar *uint &x)
{for (int i=0;i {if(!strcmp(g.vertices[i].nameu))
{x=i;return 1;
}
}
return 0;
}
void GetVex(Graph gint iVNode* &v)
{if (i {v=&g.vertices[i];
}
v=NULL;
}
void InsertVex(Graph &gVNode v)
{strcpy(g.vertices[g.vexnum].namev.name);
strcpy(g.vertices[g.vexnum].infov.info);
g.vertices[g.vexnum].firstarc=NULL;
g.vexnum++;
}
void InserArc(Graph &gint vint wint length)
{ if(v>=g.vexnum||w>=g.vexnum)
exit(0);
else
{ArcNode *temp=(ArcNode *)malloc(sizeof(ArcNode))*temp2=(ArcNode *)malloc(sizeof(ArcNode));
temp->length=length;temp->adjvex=w;temp->nextarc=NULL;
temp2->length=length;temp2->adjvex=v;temp2->nextarc=NULL;
if(!g.vertices[v].firstarc)
g.vertices[v].firstarc=temp;
else
{temp->nextarc=g.vertices[v].firstarc;
g.vertices[v].firstarc=temp;
}
if(!g.vertices[w].firstarc)
g.vertices[w].firstarc=temp2;
else
{temp2->nextarc=g.vertices[w].firstarc;
g.vertices[w].firstarc=temp2;
}
g.arcnum++;
}
}
bool GetNextVNode(Graph gint vint wArcNode* &next)
{if(v==w)
{next=g.vertices[v].firstarc;return 1;}
else
{ArcNode *temp=g.vertices[v].firstarc;
while (temp&&temp->adjvex!=w)
temp=temp->nextarc;
next=temp->nextarc;
return 1;
}
return 0;
}
//用于保存路径的函数
void InitPath(Path &pa)
{for (int i=0;i {pa.Pathlength[i]=0;pa.Pathway[i][0]=0;}
pa.length=0;
}
void CopyPath(Path &paStack S)
{pa.Pathway[pa.length][0]=S.top;
for(int i=0;i pa.Pathway[pa.length][i+1]=S.a[i];
pa.length++;
}
Path FindPath(Graph gint vint w)
{Stack S;Path Pa;int xy;
int *record=(int *)malloc(g.vexnum*sizeof(int));
for (int i=0;i {record[i]=i;
}
InitStack(S);InitPath(Pa);
VNode temp;ArcNode *next;
temp=g.vertices[v];
Push(Sv);
GetNextVNode(gvvnext);
record[v]=next->adjvex;
while(S.top)
{
if(next)
{x=next->adjvex;
if(!InStack(Sx))
{Push(Sx);
if(x==w)
{
CopyPath(PaS);
Pop(Sy);
GetTop(Sy);
GetNextVNode(gyrecord[y]next);
record[y]=next?next->adjvex:y;
}
else
GetNextVNode(gxrecord[x]next);
record[x]=next?next->adjvex:x;
}
else
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 35164 2011-12-10 18:27 校园导游图\Debug\main.obj
文件 33792 2011-12-12 12:24 校园导游图\Debug\vc60.idb
文件 53248 2011-12-10 18:27 校园导游图\Debug\vc60.pdb
文件 180297 2011-12-10 18:27 校园导游图\Debug\校园导游图.exe
文件 370140 2011-12-10 18:27 校园导游图\Debug\校园导游图.ilk
文件 226100 2011-12-10 16:42 校园导游图\Debug\校园导游图.pch
文件 484352 2011-12-10 18:27 校园导游图\Debug\校园导游图.pdb
文件 8384 2011-12-10 18:27 校园导游图\main.cpp
文件 4337 2011-12-05 21:53 校园导游图\校园导游图.dsp
文件 530 2011-12-05 21:15 校园导游图\校园导游图.dsw
文件 50176 2011-12-11 00:14 校园导游图\校园导游图.ncb
文件 48640 2011-12-11 00:14 校园导游图\校园导游图.opt
文件 1553 2011-12-10 18:27 校园导游图\校园导游图.plg
目录 0 2011-12-29 17:49 校园导游图\Debug
目录 0 2011-12-29 17:49 校园导游图
----------- --------- ---------- ----- ----
1496713 15
相关资源
- S7-300全套模块接线图
- Visio大全模具(含Cisco、IBM等常用拓扑
- 遥感图像几何校正模型探讨
- 开源1A锂电池充电板TP4056原理图+PCB
- axure 框架图模板设计.rp
- Scratch 变脸(将人物图片变成各种各样
- 普通心理学思维导图
- 计算机图形学 边填充算法实现代码
- Visio图标-最新最全的网络通信图标库
- 联想W520/T520笔记本电脑电路原理图
- LED灯串电路图说明
- 三星DDR800内存条PCB文件和原理图
- 图像的小波包分解
- SigmaPlot教程之各种柱形图的数据排列
- 嵌入式图形界面MiniGUI的示例程序9例
- PowerBuilder*图书馆管理系统*需求分析
- 数据结构年终考题范围和答案 耿国华
- 图像二维小波变换的实现源代码
- 八三编码器设计 VHDL代码 简单,包附
- 基于MFC扩展CListCtrl子项显示图片并叠
- 数据库课设:图书管理系统报告
- NE555电路应用原理图及PCB
- 在大图中查找小图显示位置
- 数据结构 朱战力 习题解答 数据结构
- 计算机图形学课设 画板
- 图论软件包(图论里的程序)
- silicon lab公司的收音IC SI47XX全套开发工
- 图像二值化
- 加密cad图形的lisp文件
- 在高斯白噪声信道下的QPSK编码误码率
评论
共有 条评论