1 #include <stdio.h>
2 #include <stdlib.h>
3
4 typedef struct node* link;
5 struct node{
6 int v;
7 link next;
8 };
9
10 link New(int v, link l){
11 link x = malloc(sizeof *x);
12 x->v = v;
13 x->next = l;
14 return x;
15 }
16
17 void main(){
18 int i;
19 int j;
20 int V = 13;
21 link arr[V];
22 for(i = 0; i<V; i++){
23 arr[i] = NULL;
24 }
25 i = 7;
26 j = 1;
27 arr[j] = New(i, arr[j]);
28 arr[j] = New(i, arr[j]);
29 arr[i] = New(j, arr[i]);
30 for(i = 0; i<V; i++){
31 printf("%d", i);
32 link t= arr[i];
33 while(t != NULL){
34 printf(" %d ", t->v);
35 t = t->next;
36 }
37 printf("\n");
38 }
39}
算法c语言实现 3-19 图的邻接表示法
最新推荐文章于 2024-05-30 14:38:37 发布