⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 深度生成森林.cpp

📁 数据结构中关于图的操作,含多种操作方法例子
💻 CPP
字号:
#include"h.h"

void dfsforest(graph g,cstree &t)
{
	t=NULL;
	for(v=0;v<g.vexnum;++v)
		visited[v]=0;
	for(v=0;v<g.vexnum;++v)
		if(!visited[v])
		{
			p=(cstree)malloc(sizeof(csnode));
			*p={ getvex(g,v),NULL,NULL};
			if(!t)	t=p;
			else q->nextsibling=p;
			q=p;
			dfstree(g,v,p);
		}
}

void dfstree(graph g,int v,cstree &t)
{
	visited[v]=1;
	first=1;
	for(w=firstadjvex(g,v);w>=0;w=nextsdjvex(g,v,w))
		if(!visited[w])
		{
			p=(cstree)malloc(sizeof(csnode));
			*p={ getvex(g,w),NULL,NULL};
			if(first)
			{
				t->lchild=p;
				first=0;
			}
			else q->nextsibling=p;
			q=p;
			dfstree(g,w,q);
		}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -