//头文件
#include<stdio.h>
#include<malloc.h>
#define N 10 //图的最大顶点数
typedef struct ArcNode //定义边表结点
{
int adjvex;
struct ArcNode *next;
} ArcNode;
typedef struct //定义顶点表结点
{
int vertex;
ArcNode *firstedge;
} VertexNode;
typedef struct //定义邻接表存储结构
{
VertexNode adjlist[N]; //存放顶点表的数组
int vertexNum, arcNum; //图的顶点数和边数
} ALGraph;
void InitGraph(ALGraph *G, int n, int e);
int main()
{
int n,e; //n为顶点数,e为边的条数
ALGraph MG;
printf("请输入图的顶点数和边的条数(用空格作为分隔符):\n");
scanf("%d%d",&n,&e);
InitGraph(&MG,n,e);
}
void InitGraph(ALGraph *G, int n, int e)
{
ArcNode *s;
int a[N];
int i,j,k,x;
int count=0;
G->vertexNum = n;
G->arcNum = e;
for (i = 0; i < G->vertexNum; i++)
{
G->adjlist[i].vertex = a[i]; //存储顶点信息
G->adjlist[i].firstedge = NULL; //初始化顶点表
}
for (k = 0; k < G->arcNum; k++) //依次输入每一条边
{
printf("请输入边依附的两个顶点的编号(用空格作为分隔符):\n");
scanf("%d%d",&i,&j); //输入边所依附的两个顶点的编号
s = (ArcNode *)malloc(sizeof(ArcNode));
s->adjvex = j;
s->next = G->adjlist[i].firstedge;
G->adjlist[i].firstedge = s;
}
printf("图的建立成功\n");
printf("请输入要求度的顶点编号:\n");
scanf("%d",&x);
for (j = 0; j < G->vertexNum; j++) //求某顶点的度
{
if (G->adjlist[x].firstedge->next != NULL)
{
count++;
}
}
printf("该顶点的度为:\n");
printf("%d\n",count);
printf("请输入要求领结点的顶点编号:\n");
scanf("%d",&x);
} 谁能帮帮忙