数据结构_简单的多叉树

简单的多叉树,可以实现从叶子节点遍历到根 和 从根遍历叶子节点的过程:


#include 
#include 
#include 

using namespace std;

enum
{
	SCHOOL,
	GRADE,
	CLASS
};



class Node
{
public :
	Node():father(NULL),level(0)
	{
		ChildList.clear();
		this->content = "";
	}
	Node(int level, string content):father(NULL)
	{
		ChildList.clear();
		this->level = level;
		this->content = content;
	}
public:
	vector ChildList;
	Node* father;
	int level;
	string content;
};


void Reverse(Node root)
{
	if(root.ChildList.size() == 0)
		return;
	else
	{
		for(int i =0; i<(root.ChildList.size()); i++)
		{
			Reverse(root.ChildList[i]);
			cout<

程序运行的效果截图

数据结构_简单的多叉树_第1张图片

你可能感兴趣的:(数据结构)