首页 > 其他 > 详细

简易邻接表

时间:2019-10-08 22:03:33      阅读:73      评论:0      收藏:0      [点我收藏+]
#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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!