快速复习一遍二叉树,加强大脑记忆

二叉树的自动创建:

#include <stdio.h>//库文件,可忽略
#include<string.h>
#include<iostream>
#include <fstream>
#include<time.h>
#include<math.h>
#define MCX 20//没有什么含义
using namespace std;
template<class T>//模板类,方便各种类型的二叉树
class M_x
{
public:
	T q;//       存储的值
	M_x* a;//    指向左边子节点的指针
	M_x* d;//    指向右边子节点的指针
	int m;//    存储这个节点的孩子的个数
};
template<class  T/*,class U*/>//T指类名
int max(T *p/*,U x*/)//递归函数
{ 
	cout << "该节点的值是多少" << endl;
	T* j = new(T);
	cin >> j->q;
	if (p->q > j->q)
	{
		p->a = j;
	}
	else if (p->q < j->q)
	{
		p->d = j;
	}
	//int xx = U;
	
	cout << "您要创建几个儿子" << endl;
	cin >> j->m;
	int i = j->m;
	if (i <= 2&&i!=0)
	{
		while (i)
		{
			max(j);
			--i;
		}
	}
	else
	{
		return 0;
	}
}
int main()

{    
	M_x<int>head;
	head.q = 10;
	max<M_x<int>>(&head);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值