Return to Snippet

Revision: 68538
at January 19, 2015 08:54 by elvis_popovic


Initial Code
#ifndef __POKAZIVAC__
#define __POKAZIVAC__
#include <iostream>
namespace stablo_pokazivac{


struct element{
	float label;
	struct element *left, *right;
};	

element *LeftChildB(element *n, element *T){
	return n->left;
}

element *RightChildB(element *n, element *T){
	return n->right;
}

float LabelB(element *n, element *T){
	return n->label;
}

void ChangeLabelB(float x, element *n, element *T){
	n->label=x;
}

element *RootB(element *T)
{
	return T;
}

bool CreateLeftB(float x, element *n, element *T){
	if(n->left) return false;
	element *novi=new element;
	novi->left=NULL;
	novi->right=NULL;
	novi->label=x;
	n->left=novi;
}
bool CreateRightB(float x, element *n, element *T){
	if(n->right) return false;
	element *novi=new element;
	novi->left=NULL;
	novi->right=NULL;
	novi->label=x;
	n->right=novi;
}

void DeleteB(element *n, element *T)
{
	if(n->left) DeleteB(n->left,T);
	if(n->right) DeleteB(n->right,T);
	delete n;
}

element *ParentB(element *n, element *T)
{
	if(T->left==n||T->right==n) return NULL;
	if(T->left->left!=n&&T->left->right!=n) ParentB(n,T->left);
		else return T->left;
	if(T->right->left!=n&&T->right->right!=n) ParentB(n,T->right);
		else return T->right;		
	
};

};
#endif

Initial URL

                                

Initial Description
Here is pointer implementation, not tested finally.

Initial Title
Binary tree, implementation using pointers and linked lists

Initial Tags
list

Initial Language
C++