文章

60

粉丝

361

获赞

41

访问

497.6k

头像
签到题
P1411 华中科技大学机试题
发布于2021年1月19日 17:17
阅读数 7.3k

#include <iostream>
#include <string>
#include <string.h>
using namespace std;

typedef struct node
{
	int data;
	struct node *lchild,*rchild;
}*tree;

void paixu(tree &T,int temp)
{
	if(T==NULL)
	{
		T=new node;
		T->data=temp;
		T->lchild =NULL;
		T->rchild=NULL;
		return;
	}
	else
	{
		if(temp==T->data)
			return;
		else if(temp<T->data)
			paixu(T->lchild ,temp);
		else if(temp>T->data)
			paixu(T->rchild ,temp);
	}
	return;
}
void preorder(tree T)
{
	if(T!=NULL)
	{
		cout<<T->data<<" " ;
		preorder(T->lchild);
		preorder(T->rchild);
	}
}
void midorder(tree T)
{
	if(T!=NULL)
	{
		midorder(T->lchild);
		cout<<T->data<<" " ;
		midorder(T->rchild);
	}
}
void posorder(tree T)
{
	if(T!=NULL)
	{
		posorder(T->lchild);
		posorder(T->rchild);
		cout<<T->data<<" " ;
	}
}
int main()
{
	int n;
	int temp;
	while(c...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发