# 纸上谈兵: 图 (graph)

+关注继续查看

(这个问题在许多奥数教材中称为"一笔画"问题)

### 图的定义

(七桥问题中的图是无向的。城市中的公交线路可以是无向的，比如存在单向环线)

### 图的实现

 a 1 2 3 1 0 1 1 2 0 0 0 3 0 1 0

/* By Vamei */
#include <stdio.h>
#include <stdlib.h>

#define NUM_V 5

typedef struct node *position;

/* node */
struct node {
int element;
position next;
};

/*
* operations (stereotype)
*/
void insert_edge(position, int, int);
void print_graph(position graph, int nv);

/* for testing purpose */
void main()
{
struct node graph[NUM_V];
int i;

// initialize the vertices
for(i=1; i<NUM_V; i++) {
(graph+i)->element = i;
(graph+i)->next    = NULL;
}

// insert edges
insert_edge(graph,1,2);
insert_edge(graph,1,4);
insert_edge(graph,3,2);
insert_edge(graph,4,2);
insert_edge(graph,4,3);

print_graph(graph,NUM_V);
}

/* print the graph */
void print_graph(position graph, int nv) {
int i;
position p;
for(i=1; i<nv; i++) {
p = (graph + i)->next;
printf("From %3d: ", i);
while(p != NULL) {
printf("%d->%d; ", i, p->element);
p = p->next;
}
printf("\n");
}
}

/*
* insert an edge
*/
void insert_edge(position graph,int from, int to)
{
position np;

np = graph + from;

}

From   1: 1->4; 1->2;
From   2:
From   3: 3->2;
From   4: 4->3; 4->2;

### 总结

64 0
PGL图学习之基于UniMP算法的论文引用网络节点分类任务[系列九]
PGL图学习之基于UniMP算法的论文引用网络节点分类任务[系列九]
46 0
PGL图学习之图神经网络GraphSAGE、GIN图采样算法[系列七]
PGL图学习之图神经网络GraphSAGE、GIN图采样算法[系列七]
170 0
PGL图学习之图游走类metapath2vec模型[系列五]

174 0
44 0

222 0
Deep Graph Infomax：互信息最大化的无监督图对比学习
Deep Graph Infomax：互信息最大化的无监督图对比学习
234 0

60 0

190 0

105 0
+关注
vamei