#include<stdio.h>
#include<stdlib.h>
#define V 8
typedef struct node* link;
struct node
{
int item;
link next;
};
link NewNode(int ,link);
main()
{
int i,j;
link adj[V];
for(i=0;i<V;i++)
{
adj[i]=NULL;
}
printf("Please enter the pairs which adjioned:(q to end)\n");
while(scanf("%d %d",&i,&j)==2)
{
adj[i]=NewNode(j,adj[i]);
adj[j]=NewNode(i,adj[j]);
}
}
link NewNode(int n,link x)
{
link y=malloc(sizeof *y);
y->item=n;
y->next=x;
return y;
}
使用邻接表实现的无向图
最新推荐文章于 2022-07-01 16:39:33 发布