首页 > 代码库 > 二叉树练习(未完成)

二叉树练习(未完成)

#include "stdafx.h"
#include<iostream>
using namespace std;
///////队列///////////////////////////////////////

typedef struct Tree {
	int key;
	Tree* p;
	Tree* left;
	Tree* right;
}Tree;
typedef Tree* TreeNode;

TreeNode Insert(TreeNode T, int x, TreeNode p)
{
	if (T == NULL) {
		T = (TreeNode)malloc(sizeof(int));
		T->key = x;
		T->left = NULL;
		T->right = NULL;
		T->p = p;
	}
	else if(x!=T->key) {
		p = T;
		if (x < T->key)  Insert(T->left, x, p);
		else if(x > T->key)  Insert(T->right, x, T);
	}
	return T;
}

void Init(TreeNode T, int key[],int n)
{
	for (int i = 1; i <= n; i++)
		Insert(T, key[i], NULL);
}

void printTree(TreeNode T)
{

}

int main()
{
	TreeNode T=NULL;
	int key[8] = { 0,5,9,6,2,4,1,3 };
	Init(T, key,7);
	while (1);
    return 0;
}

  

二叉树练习(未完成)