头文件:‘1.h’
#include <stdio.h>
#include <iostream>
#include <malloc.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
#define ERROR 0
typedef int Status;
using namespace std;
头文件:‘2.h’
#include "1.h"
#define MAX_VERTEX 20
typedef char VertexType;
typedef struct ArcNode
{
int adjvex;
struct ArcNode *nextarc;
}ArcNode;
typedef struct VNode
{
VertexType data;
ArcNode *firstarc;
}VNode,AdjList[MAX_VERTEX];
typedef struct
{
AdjList vertices;
int vexnum, arcnum;
int kind;
}ALGraph;
//队列
typedef int QElemtype;
#define MAXQSIZE 100
typedef struct
{
QElemtype *base;
int front;
int rear;
}SqQueue;
头文件:‘3.h’(函数的实现)
#pragma once
#include "2.h"
Status LovateVex(ALGraph &G, VertexType v)
{
int i;
for (i = 0; i < G.vexnum; i++)
{
if (G.vertices[i].data == v)
return i;
}
}
Status CreatDG(ALGraph &G)//创建有向图
{
VertexType v1, v2;
int j, k;
ArcNode *p;
cout << "输入定点个数和边数:";
cin >> G.vexnum >> G.arcnum;
int i;
cout << "输入顶点个数和边数:";
for (i = 0; i < G.vexnum; i++)
{
cin >> G.vertices[i].data;
G.vertices[i].firstarc =N