资源简介
数据结构,使用C语言编写的求关键路径的源代码
代码片段和文件信息
#include
#include
#include
using namespace std;
#define MAX_VERTEX_NUM 20 //顶点的最大数
#define INIT_SIZE 100 //堆栈的初始化大小
#define INCREMENT 10 //堆栈的增量
#define OK 1
#define ERROR -1
//堆栈的存储结构
typedef struct{int *top;int *base;int stacksize;}Stack;
//弧结点
typedef struct ArcNode{
int adjvex;
struct ArcNode *nextarc;
int info;
}ArcNode*ArcPtr;
//顶点结点
typedef struct VNode{
char data;
ArcNode *firstarc;
}VNodeAdjList[MAX_VERTEX_NUM];
//图的存储结构
typedef struct{
AdjList vertices;
int vexnumarcnum;
}ALGraph;
int adjvex[MAX_VERTEX_NUM][MAX_VERTEX_NUM]={0};//各顶点的邻接顶点
//确定顶点在图中的位置
int LocateVex(ALGraph Gchar ch)
{
for(int i=0;i if(ch==G.vertices[i].data) return i;
return -1;
}
//创建图
void CreateGraph(ALGraph &G)
{
ArcNode *p;
char v1v2;int *jinfo;
int mn;
for(m=0;m for(n=0;n adjvex[m][n]=-1;
cout<<“Enter the number of vertices and arcs:\n“;
cin>>G.vexnum>>G.arcnum;
j=new int[G.vexnum];
cout<<“Enter the vertices:\n“;
for(int i=0;i {
cin>>G.vertices[i].data;
G.vertices[i].firstarc=NULL;
j[i]=0;
}
for(int k=0;k {
p=new ArcNode;
cout<<“Enter the arcs:\n“;
cin>>v1>>v2>>info;
m=LocateVex(Gv1);n=LocateVex(Gv2);
adjvex[m][j[m]++]=n;
p->adjvex=n;
p->info=info;
p->nextarc=G.vertices[m].firstarc;
G.vertices[m].firstarc=p;
}
}
//输出邻接表
void PrintTable(ALGraph G)
{
ArcNode *p;
cout<<“\n邻接表:\n\n“;
for(int i=0;i {
cout<“;
p=G.vertices[i].firstarc;
while(p)
{
cout<adjvex<<“-“<info<<“-->“;
p=p->nextarc;
}
cout<<“NULL“< }
cout< }
//深度优先遍历图========================================================
//第v个达顶点的第一个邻接顶点
int FirstAdjVex(ALGraph Gint v)
{
int w;
w=adjvex[v][0];
return w;
}
int pos(int a[][MAX_VERTEX_NUM]int vint w)
{
int j;
for(j=0;j {
if(a[v][j]==w)
return j;
}
return -1;
}
//第v个顶点的下一个邻接顶点
int NextAdjVex(ALGraph Gint vint w)
{
int n=pos(adjvexvw);
return adjvex[v][n+1];
}
//*************************建立堆栈相关的函数*************************
void InitStack(Stack &S)
{
S
相关资源
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- 学校超市选址问题(数据结构C语言版
- VC++MFC小游戏实例教程(实例)+MFC类库
- 数据结构,迷宫问题C语言版源代码
- DSDEMO-C演示(数据结构C语言版 严蔚敏
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- 数据结构 图的遍历源代码
- 数据结构实验源代码集
- 实验报告:数据结构长整数四则运算
评论
共有 条评论