# Posted By

Sibabic on 01/06/11

# Statistics

Viewed 344 times
Favorited by 0 user(s)

# Zadatak 4 Implementacija binarnog stabla pomocu pokazivaca

/ Published in: C++
`typedef struct element{	labeltype label;	struct element *left,*right;} bt; typedef struct element *node;typedef struct element *bTree; node p;  node RootB(bTree T){	return T;}; node LeftChildB(node n, bTree T){	return n->left;}; node RightChildB(node n, bTree T){	return n->right;}; labeltype LabelB(node n, bTree T){	return n->label;}; int ExistsLeftChild(node n, bTree T){    if (n->left == NULL)        return 0;    else        return 1;}; int ExistsRightChild(node n, bTree T){    if (n->right == NULL)        return 0;    else        return 1;}; void ChangeLabelB(labeltype x, node n, bTree T){	n->label = x;}; void CreateLeftB(labeltype x, node n, bTree T){	element *tmp = new element;	n->left = tmp;	tmp->left = NULL;	tmp->right = NULL;	tmp->label = x;}; void CreateRightB(labeltype x, node n, bTree T){	element *tmp=new element;	n->right = tmp;	tmp->left = NULL;	tmp->right = NULL;	tmp->label = x;}; void SearchParentInternal(node n, bTree T){	if (LeftChildB(T,T) != NULL)		if (T->left == n)			p = T;	else		SearchParentInternal(n, T->left);	if (RightChildB(T,T) != NULL)		if (T->right == n)			p = T;	else		SearchParentInternal(n, T->right);}; node ParentB(node n, bTree T){	SearchParentInternal(n,T);	return p;}; void DeleteB(node n, bTree T){	node tmp;	if (n != RootB(T))	{		tmp = ParentB(n,T);		if(tmp->left == n)			tmp->left = NULL;		else			tmp->right = NULL;	}	if(n->left != NULL)		DeleteB(n->left, T);	if(n->right != NULL)		DeleteB(n->right, T);	delete n;}; void InitB(labeltype x, bTree T){	T->label = x;	T->left = NULL;	T->right = NULL;};`