目录
一、main
#include <bits/stdc++.h>
#include "com.h"
using namespace std ;
void UDG_matrix() ; // A.无向图--邻接矩阵
void DG_matrix() ; // B.有向图--邻接矩阵
void UDG_list() ; // C.无向图--邻接表
void DG_list() ; // D.有向图--邻接表
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
char select ;
do
{
printf("\t\t\t|============================\n");
printf("\t\t\t| 请选择相关类型 |\n");
printf("\t\t\t|---------------------------|\n");
printf("\t\t\t| |\n");
printf("\t\t\t| A.无向图--邻接矩阵 |\n");
printf("\t\t\t| B.有向图--邻接矩阵 |\n");
printf("\t\t\t| C.无向图--邻接表 |\n");
printf("\t\t\t| D.有向图--邻接表 |\n");
printf("\t\t\t| E.退出整个系统 |\n");
printf("\t\t\t=============================\n");
printf("选择(A---E):\t");
cin >> select ;
switch (select)
{
case 'A' :
UDG_matrix() ; // A.无向图--邻接矩阵
cout << endl ;
break ;
case 'B' :
DG_matrix() ; // B.有向图--邻接矩阵
cout << endl ;
break ;
case 'C' :
UDG_list() ; //C.无向图--邻接表
cout << endl ;
break ;
case 'D' :
DG_list() ; // D.有向图--邻接表
cout << endl ;
break ;
case 'E' :
cout << "退出成功" ;
cout << endl ;
break ; //return 0 ;
default :
cout << "输入不合法,请重新输入" ;
cout << endl ;
}
}while(select != 'E') ;
return 0;
}
// A.无向图--邻接矩阵
void UDG_matrix()
{
AMGraph G ;
int choice , i , j ;
do
{
printf("\t\t\t|========================\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 无向图--邻接矩阵 |\n");
printf("\t\t\t|-----------------------|\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 0.返回主菜单 |\n");
printf("\t\t\t| 1.创建无向图 |\n");
printf("\t\t\t| 2.打印无向图 |\n");
printf("\t\t\t| 3.求各顶点的度 |\n");
printf("\t\t\t| 4.深度优先搜索 |\n");
printf("\t\t\t| 5.广度优先搜索 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t=========================\n");
printf("选择(0---5):\t");
cin >> choice ;
switch (choice)
{
case 0 : // 0.返回主菜单
cout << "已返回主菜单" ;
cout << endl ;
return ;
case 1 : //1.创建无向图
CreateUDG(G) ;
cout << "创建成功" ;
cout << endl ;
break ;
case 2 :
cout << "邻接矩阵为:" << endl ;
PrintUDG(G) ;
cout << endl ;
break ;
case 3 :
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << G.vexs[i] << "的度为:" << UDGDegree(G , i) ;
cout << endl ;
}
cout << endl ;
break ;
case 4 : //4.深度优先搜素
cout << "遍历结果为:" << endl ;
for(i = 0 ; i < G.vexnum ; i ++)
{
Resetting() ; // 重置 v
cout << G.vexs[i] << "为遍历点:" ;
UDGDFS(G , i) ;
cout << endl ;
}
// UDGDFS_Traverse(G) ; // 可以用到当非连通图时
cout << endl ;
break ;
case 5 :
cout << "遍历结果为:" << endl ;
for(i = 0 ; i < G.vexnum ; i ++)
{
Resetting() ; // 重置 v
cout << G.vexs[i] << "为遍历点:" ;
UDGBFS(G , i) ;
cout << endl ;
}
// UDGDFS_Traverse(G) ; // 可以用到当非连通图时
cout << endl ;
break ;
default :
cout << "输入不合法,请重新输入" ;
cout << endl ;
}
}while(choice != 0) ;
}
/*
A B
A C
B D
*/
// B.有向图--邻接矩阵
void DG_matrix()
{
AMGraph G ;
int choice , i , j ;
do
{
printf("\t\t\t|========================\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 有向图--邻接矩阵 |\n");
printf("\t\t\t|-----------------------|\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 0.返回主菜单 |\n");
printf("\t\t\t| 1.创建有向图 |\n");
printf("\t\t\t| 2.打印有向图 |\n");
printf("\t\t\t| 3.求各顶点的度 |\n");
printf("\t\t\t| 4.求各顶点的入度 |\n");
printf("\t\t\t| 5.求各顶点的出度 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t=========================\n");
printf("选择(0---5):\t");
cin >> choice ;
switch (choice)
{
case 0 : // 0.返回主菜单
cout << "已返回主菜单" ;
cout << endl ;
return ;
case 1 : //1.创建无向图
CreateDG(G) ;
cout << "创建成功" ;
cout << endl ;
break ;
case 2 :
cout << "邻接矩阵为:" << endl ;
PrintUDG(G) ;
cout << endl ;
break ;
case 3 : // 3.求各顶点的度
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << G.vexs[i] << "的度为:" << DGDegree(G , i) ;
cout << endl ;
}
cout << endl ;
break ;
case 4 : // // 4.求各顶点的入度
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << G.vexs[i] << "的入度为:" << INDGDegree(G , i) ;
cout << endl ;
}
cout << endl ;
break ;
case 5 : // 5.求各顶点的出度
for(i = 0 ; i < G.vexnum ; i ++) //
{
cout << G.vexs[i] << "的出度为:" << OUTDGDegree(G , i) ;
cout << endl ;
}
cout << endl ;
break ;
default :
cout << "输入不合法,请重新输入" ;
cout << endl ;
}
}while(choice != 0) ;
}
// C.无向图--邻接表
void UDG_list()
{
ALGraph G ;
int choice , i , j ;
do
{
printf("\t\t\t|========================\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 无向图--邻接表 |\n");
printf("\t\t\t|-----------------------|\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 0.返回主菜单 |\n");
printf("\t\t\t| 1.创建无向图 |\n");
printf("\t\t\t| 2.打印邻接表 |\n");
printf("\t\t\t| 3.求各顶点的度 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t=========================\n");
printf("选择(0---3):\t");
cin >> choice ;
switch (choice)
{
case 0 : // 0.返回主菜单
cout << "已返回主菜单" ;
cout << endl ;
return ;
case 1 : //1.创建无向图
CreateUDG_AL(G) ;
cout << "创建成功" ;
cout << endl ;
break ;
case 2 : // 2.打印邻接表
cout << "邻接表为:" << endl ;
PrintUDG_AL(G) ;
cout << endl ;
break ;
case 3 :
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << G.vertices[i].data << "的度为:" << UDGDegree_AL(G , i) ;
cout << endl ;
}
cout << endl ;
break ;
default :
cout << "输入不合法,请重新输入" ;
cout << endl ;
}
}while(choice != 0) ;
}
// D.有向图--邻接表
void DG_list()
{
ALGraph G ;
int choice , i , j ;
do
{
printf("\t\t\t|========================\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 有向图--邻接表 |\n");
printf("\t\t\t|-----------------------|\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 0.返回主菜单 |\n");
printf("\t\t\t| 1.创建有向图 |\n");
printf("\t\t\t| 2.打印邻接表 |\n");
printf("\t\t\t| 3.求各顶点的度 |\n");
printf("\t\t\t| 4.求各顶点的入度 |\n");
printf("\t\t\t| 5.求各顶点的出度 |\n");
printf("\t\t\t| 6.深度优先搜索 |\n");
printf("\t\t\t| 7.广度优先搜索 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t=========================\n");
printf("选择(0---7):\t");
cin >> choice ;
switch (choice)
{
case 0 : // 0.返回主菜单
cout << "已返回主菜单" ;
cout << endl ;
return ;
case 1 : //1.创建无向图
CreateDG_AL(G) ;
cout << "创建成功" ;
cout << endl ;
break ;
case 2 : // 2.打印邻接表
cout << "邻接表为:" << endl ;
PrintDG_AL(G) ;
cout << endl ;
break ;
case 3 :
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << G.vertices[i].data << "的度为:" << INDGDegree_AL(G , i)+UDGDegree_AL(G , i) ;
cout << endl ;
}
cout << endl ;
break ;
case 4 : //4.求各顶点的入度
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << G.vertices[i].data << "的入度为:" << INDGDegree_AL(G , i) ;
cout << endl ;
}
cout << endl ;
break ;
case 5 : //5.求各顶点的出度
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << G.vertices[i].data << "的出度为:" << UDGDegree_AL(G , i) ;
cout << endl ;
}
cout << endl ;
break ;
case 6 : // 6.深度优先搜素
cout << "遍历结果为:" << endl ;
for(i = 0 ; i < G.vexnum ; i ++)
{
Resetting() ; // 重置 v
cout << G.vertices[i].data << "为遍历点:" ;
DGDFS_AL(G , i) ;
cout << endl ;
}
// UDGDFS_Traverse(G) ;
cout << endl ;
break ;
case 7 : // 7.广度优先搜素
cout << "遍历结果为:" << endl ;
for(i = 0 ; i < G.vexnum ; i ++)
{
Resetting() ; // 重置 v
cout << G.vertices[i].data << "为遍历点:" ;
DGBFS_AL(G , i) ;
cout << endl ;
}
cout << endl ;
break ;
default :
cout << "输入不合法,请重新输入" ;
cout << endl ;
}
}while(choice != 0) ;
}
二、function
#include <bits/stdc++.h>
#include "com.h"
using namespace std ;
//A.无向图--邻接矩阵
// 创建
Status CreateUDG(AMGraph &G)
{
cout << "请输入点的个数:" ;
cin >> G.vexnum ;
cout << "请输入边的条数: " ;
cin >> G.arcnum ;
int i , j , k , w;
VerTexType v1 , v2 ;
cout << "请输入各个点:" ;
for(i = 0 ; i < G.vexnum ; i ++)
cin >> G.vexs[i] ;
// 这个可写可不写,因为它的初始值本来就是 0
for(i = 0 ; i < G.vexnum ; i ++)
for(j = 0 ; j < G.vexnum ; j ++)
G.arcs[i][j] = 0 ;
cout << "请输入邻接关系(如:A B):" << endl ;
for(k = 0 ; k < G.arcnum ; k ++)
{
cin >> v1 >> v2 ;
i = LocateVex(G , v1) ;
j = LocateVex(G , v2) ;
if(i >= 0 && j >= 0) G.arcs[i][j] = G.arcs[j][i] = 1 ;
else cout << "该点不存在,请重新输入" << endl ;
}
return OK ;
}
//定位v在邻接矩阵中的位置
int LocateVex(AMGraph G , VerTexType v)
{
int i ;
for(i = 0 ; i < G.vexnum ; i ++)
if(G.vexs[i] == v)
return i ;
return -1 ;
}
// 打印无向图
void PrintUDG(AMGraph G)
{
int i , j , k ;
cout << "\t" ;
for(i = 0 ; i < G.vexnum ; i ++) cout << "\t" << G.vexs[i] ;
cout << endl ;
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << "\t" << G.vexs[i] ;
for(j = 0 ; j < G.vexnum ; j ++)
cout << "\t" << G.arcs[i][j] ;
cout << endl << endl ;
}
}
//求无向图各顶点的度
int UDGDegree(AMGraph G , int i)
{
int sum = 0 , j ;
for(j = 0 ; j < G.vexnum ; j ++)
if(G.arcs[i][j] == 1)
sum ++ ;
return sum ;
}
// 4.深度优先搜素
bool visited[MVNum] ;
void UDGDFS_Traverse(AMGraph G)
{
memset(visited , false , sizeof(visited)) ;
int i ;
for(i = 0 ; i < G.vexnum ; i ++)
if(!visited[i]) UDGDFS(G , i) ;
}
void Resetting()
{
memset(visited , false , sizeof(visited)) ;
}
void UDGDFS(AMGraph G , int v)
{
cout << G.vexs[v] << " " ;
visited[v] = true ;
int w ;
for(w = 0 ; w < G.vexnum ; w ++)
if(G.arcs[v][w] == 1 && !visited[w])
UDGDFS(G , w) ;
}
void UDGBFS(AMGraph G , int v) // 0
{
int u , i ;
LinkQueue Q ;
cout << G.vexs[v] << " " ; // v
visited[v] = true ; //
InitQueue(Q) ;
EnQueue(Q , v) ;
while(!QueueEmpty(Q))
{
DeQueue(Q , u) ;
for(i = 0 ; i < G.vexnum ; i ++)
{
if(!visited[i] && G.arcs[i][u] == 1)
{
cout << G.vexs[i] << " " ;
visited[i] = true ;
EnQueue(Q , i) ;
}
}
}
}
//初始化
Status InitQueue(LinkQueue &Q)
{
Q.front = Q.rear = new QNode ;
Q.front->next = NULL ; // 头指针指向空
return OK ;
}
// 判空
bool QueueEmpty(LinkQueue Q)
{
if(Q.front == Q.rear) return true ;
else return false ;
}
// 入队
Status EnQueue(LinkQueue &Q , QElemType e)
{
QueuePtr p ; // 注意,用Queueptr 定义
p = new QNode ;
p->data = e ;
p->next = NULL ; // p插入到rear后面,p的next为空
Q.rear->next = p ; // rear指向p,插入
Q.rear = p ; // rear要在最后
return OK ;
}
// 出队
Status DeQueue(LinkQueue &Q , QElemType &e)
{
if(Q.front == Q.rear) return ERROR ; // 空我,无法删除
QueuePtr p ; //
p = Q.front->next ; // 头结点的下一个,先保存在p
e = p->data ; // 将要删除的结点data传给e
Q.front->next = p->next ; // front指向下一个
if(p == Q.rear) Q.rear = Q.front ; // 如果只有一个结点
delete p ; // 删除
return OK ;
}
// B.有向图--邻接矩阵
// 建立
Status CreateDG(AMGraph &G)
{
cout << "请输入点的个数:" ;
cin >> G.vexnum ;
cout << "请输入边的条数: " ;
cin >> G.arcnum ;
int i , j , k , w;
VerTexType v1 , v2 ;
cout << "请输入各个点:" ;
for(i = 0 ; i < G.vexnum ; i ++)
cin >> G.vexs[i] ;
// 这个可写可不写,因为它的初始值本来就是 0
for(i = 0 ; i < G.vexnum ; i ++)
for(j = 0 ; j < G.vexnum ; j ++)
G.arcs[i][j] = 0 ;
cout << "请输入邻接关系(如:A B):" << endl ;
for(k = 0 ; k < G.arcnum ; k ++)
{
cin >> v1 >> v2 ;
i = LocateVex(G , v1) ;
j = LocateVex(G , v2) ;
if(i >= 0 && j >= 0) G.arcs[i][j] = 1 ;
else cout << "该点不存在,请重新输入" << endl ;
}
return OK ;
}
// 3.求各顶点的度
int DGDegree(AMGraph G , int i)
{
int j , sum = 0 ;
for(j = 0 ; j < G.vexnum ; j ++)
if(G.arcs[i][j] == 1 || G.arcs[j][i] == 1)
sum ++ ;
return sum ;
}
//4.求各顶点的入度
int INDGDegree(AMGraph G , int i)
{
int j , sum = 0 ;
for(j = 0 ; j < G.vexnum ; j ++)
if(G.arcs[j][i] == 1)
sum ++ ;
return sum ;
}
//5.求各顶点的出度
int OUTDGDegree(AMGraph G , int i)
{
int j , sum = 0 ;
for(j = 0 ; j < G.vexnum ; j ++)
if(G.arcs[i][j] == 1)
sum ++ ;
return sum ;
}
// C.无向图--邻接表
// 创建
Status CreateUDG_AL(ALGraph &G)
{
cout << "请输入点的个数:" ;
cin >> G.vexnum ;
cout << "请输入边的条数: " ;
cin >> G.arcnum ;
int i , j , k , w;
VerTexType v1 , v2 ;
ArcNodeList p1 , p2 ;
cout << "请输入各个点:" ;
for(i = 0 ; i < G.vexnum ; i ++)
{
cin >> G.vertices[i].data ;
G.vertices[i].firstarc = NULL ;
}
cout << "请输入邻接关系(如:A B):" << endl ;
for(k = 0 ; k < G.arcnum ; k ++)
{
cin >> v1 >> v2 ;
i = LocateVex_AL(G , v1) ;
j = LocateVex_AL(G , v2) ;
if(i < 0 || j < 0)
{
cout << "该点不存在,请重新输入" << endl ;
continue ;
}
p1 = new ArcNode ;
p1->adjvex = j ;
p1->nextarc = G.vertices[i].firstarc ;
G.vertices[i].firstarc = p1 ;
p2 = new ArcNode ;
p2->adjvex = i ;
p2->nextarc = G.vertices[j].firstarc ;
G.vertices[j].firstarc = p2 ;
}
return OK ;
}
int LocateVex_AL(ALGraph G , VerTexType v)
{
int i ;
for(i = 0 ; i < G.vexnum ; i ++)
if(G.vertices[i].data == v)
return i ;
return -1 ;
}
// 2.打印邻接表
void PrintUDG_AL(ALGraph G)
{
int i , j ;
ArcNodeList temp ;
cout << "邻接表顶点有:" ;
for(i = 0 ; i < G.vexnum ; i ++)
cout << G.vertices[i].data << " " ;
cout << endl ;
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << i << ":" << G.vertices[i].data << "->" ;
temp = G.vertices[i].firstarc ;
while(temp)
{
if(temp->nextarc) cout << G.vertices[temp->adjvex].data << "->" ;
else cout << G.vertices[temp->adjvex].data << "->NULL" ;
temp = temp->nextarc ;
}
cout << endl ;
}
}
// 3.求各顶点的度(不存在出度入度比较容易)
int UDGDegree_AL(ALGraph G , int i)
{
int j , sum = 0 ;
ArcNodeList temp ;
temp = G.vertices[i].firstarc ;
while(temp)
{
sum ++ ;
temp = temp->nextarc ;
}
return sum ;
}
// D.有向图--邻接表
// 创建
Status CreateDG_AL(ALGraph &G)
{
int i , j , k ;
VerTexType v1 , v2 ;
ArcNodeList p ;
cout << "请输入点的个数:" ;
cin >> G.vexnum ;
cout << "请输入边的条数:" ;
cin >> G.arcnum ;
cout << "请输入各个点:" ;
for(i = 0 ; i < G.vexnum ; i ++)
{
cin >> G.vertices[i].data ;
G.vertices[i].firstarc = NULL ;
}
cout << "请输入邻接关系(如:A B):" << endl ;
for(k = 0 ; k < G.arcnum ; k ++)
{
cin >> v1 >> v2 ;
i = LocateVex_AL(G , v1) ;
j = LocateVex_AL(G , v2) ;
p = new ArcNode ;
p->adjvex = j ;
p->nextarc = G.vertices[i].firstarc ;
G.vertices[i].firstarc = p ;
}
return OK ;
}
// 2.打印邻接表
void PrintDG_AL(ALGraph G)
{
int i , j ;
ArcNodeList temp ;
cout << "邻接表顶点有:" ;
for(i = 0 ; i < G.vexnum ; i ++)
cout << G.vertices[i].data << " " ;
cout << endl ;
for(i = 0 ; i < G.vexnum ; i ++)
{
cout << i << ":" << G.vertices[i].data << "->" ;
temp = G.vertices[i].firstarc ;
while(temp)
{
cout << G.vertices[temp->adjvex].data << "->" ;
temp = temp->nextarc ;
}
cout << "NULL" ;
cout << endl ;
}
}
求点的度
//int DGDegree_AL(ALGraph G , int i)
//{
//
//}
int INDGDegree_AL(ALGraph G , int i)
{
int j , k , sum = 0;
ArcNodeList temp ;
for(j = 0 ; j < G.vexnum ; j ++)
{
if(j == i) continue ;
temp = G.vertices[j].firstarc ;
while(temp)
{
if(temp->adjvex == i) sum ++ ;
temp = temp->nextarc ;
}
}
return sum ;
}
// 6.深度优先搜素
void DGDFS_AL(ALGraph G , int i)
{
cout << G.vertices[i].data ;
visited[i] = true ;
int j , k ;
ArcNodeList temp ;
temp = G.vertices[i].firstarc ;
while(temp)
{
j = temp->adjvex ;
if(!visited[j]) DGDFS_AL(G , j) ;
temp = temp->nextarc ;
}
}
// 7 广
void DGBFS_AL(ALGraph G , int v)
{
int u , i ;
LinkQueue Q ;
ArcNodeList temp ;
cout << G.vertices[v].data << " ";
visited[v] = true ;
InitQueue(Q) ;
EnQueue(Q , v) ; // 点
while(!QueueEmpty(Q))
{
DeQueue(Q , u) ;
temp = G.vertices[u].firstarc ;
while(temp)
{
i = temp->adjvex ; // i
if(!visited[i])
{
cout << G.vertices[i].data << " " ;
visited[i] = true ;
EnQueue(Q , i) ;
}
temp = temp->nextarc ;
}
}
}
三、main
#define OK 1
#define ERROR 0
typedef int Status ;
//
typedef int QElemType ;
typedef struct QNode
{
QElemType data ;
struct QNode *next ;
}QNode , *QueuePtr ;
typedef struct
{
QueuePtr front ;
QueuePtr rear ;
}LinkQueue ;
extern Status InitQueue(LinkQueue &Q) ;
extern bool QueueEmpty(LinkQueue Q) ;
extern Status EnQueue(LinkQueue &Q , QElemType e) ;
extern Status DeQueue(LinkQueue &Q , QElemType &e) ;
// 邻接矩阵
#define MaxInt 0
#define MVNum 24 //自定义,不想太大
typedef char VerTexType ;
typedef int ArcType ;
typedef struct{
VerTexType vexs[MVNum] ; //字符型 点
ArcType arcs[MVNum][MVNum] ; //各个点之间是否有关系 0 1
int vexnum , arcnum ; // 点 边 的个数
}AMGraph;
//A.无向图--邻接矩阵
extern Status CreateUDG(AMGraph &G) ; // 创建无向图
extern int LocateVex(AMGraph G , VerTexType v) ;//定位v在邻接矩阵中的位置
extern void PrintUDG(AMGraph G) ; // 打印无向图
extern int UDGDegree(AMGraph G , int i) ; // //求无向图各顶点的度
extern void UDGDFS_Traverse(AMGraph G) ; // 4.深度优先搜素
extern void UDGDFS(AMGraph G , int v) ;
extern void Resetting() ; // 重置 v
extern void UDGBFS(AMGraph G , int v) ;
// B.有向图--邻接矩阵
extern Status CreateDG(AMGraph &G) ;
extern int DGDegree(AMGraph G , int i) ;
extern int INDGDegree(AMGraph G , int i) ;
extern int OUTDGDegree(AMGraph G , int i);
// 邻接表
typedef int OtherInfo ;
typedef struct ArcNode{
int adjvex ; //每个点的下标值
struct ArcNode *nextarc ; //下一个相邻点
OtherInfo info ; // 1 0 , 最要用于网中,图中可以不用
}ArcNode , *ArcNodeList;
typedef struct VNode{
VerTexType data ; //字符型 ,每一个具体的点VerTexType
ArcNode *firstarc ;
}VNode , AdjList[MVNum];
typedef struct{
AdjList vertices ; //邻接表,vexnum个点
int vexnum , arcnum ; //点 边
}ALGraph;
// C.无向图--邻接表
extern Status CreateUDG_AL(ALGraph &G) ; // 创建
extern int LocateVex_AL(ALGraph G , VerTexType v) ;
extern void PrintUDG_AL(ALGraph G) ; // 2.打印邻接表
extern int UDGDegree_AL(ALGraph G , int i) ;
extern Status CreateDG_AL(ALGraph &G) ; //创建
// D.有向图--邻接表
extern Status CreateDG_AL(ALGraph &G) ;
extern void PrintDG_AL(ALGraph G) ;
extern int INDGDegree_AL(ALGraph G , int i) ; // 入度
extern void DGDFS_AL(ALGraph G , int i) ; // dfs
extern void DGBFS_AL(ALGraph G , int v) ; // bfs