9天没有摸C语言,手很生啊!
唉,考试终于结束了,就剩三门了。
算法、数据结构太重要了,不要忽视啊!
#include <bits/stdc++.h>
using namespace std;
#define MAXSIZE 100
int v[MAXSIZE];//标志位,判断该结点有没有被访问
typedef struct ArcNode //定义表节点
{
int adjvex;
struct ArcNode *next;
}ArcNode;
typedef struct VNode //定义头结点
{
int data;
ArcNode *firstarc;
}VNode,AdjList[MAXSIZE];
typedef struct //定义图的整体数据结构
{
int vexnum,arcnum;//边数、弧数
AdjList vertices;
}ALGraph;
void Init(ALGraph &G)//初始化无向图
{
int i,n,m,a,b;
ArcNode *s;
cin>>n>>m;
G.arcnum=m;
G.vexnum=n;
for(i=1;i<=G.vexnum;i++)//初始化
{
G.vertices[i].firstarc=NULL;//一开始都指向NULL
G.vertices[i].data=i;//初始化节点编号从1~n
}
for(i=0;i<G.arcnum;i++)