#include <bits/stdc++.h> using namespace std; struct node { int val; node* nex; } ; node a[100]; void build(int v1, int v2) { node* p, * next; if (a[v1].val==0) { a[v1].val = v2; } else { p = &a[v1]; while (p->nex != NULL) { p = p->nex; } next = (node*)malloc(sizeof(node*)); next->val = v2; p->nex = next; next->nex = NULL; } } void writes(int v) { node* p, * next; p = &a[v]; cout << v << ": "; while (p->nex != NULL) { cout << p->val << " "; p = p->nex; } cout << p->val << endl; cout << "終わる" << endl; } int main() { int v1 = 0, v2 = 0; while (v1 != 114) { cin >> v1 >> v2; build(v1, v2); writes(v1); } }
我本来想在网上搜的,他妈的,一会template一会儿struct,完全看不懂。
自己写了。
超简易的邻接表。
原理自己百度吧
原文:https://www.cnblogs.com/asanagiyantia/p/11637490.html