Return to Snippet

Revision: 68441
at January 18, 2015 14:37 by 8ivana8


Initial Code
struct pok_element{
	int label;
	pok_element* left, * right;
};

pok_element* InitB(int x, pok_element* T){
	T = new pok_element;
	T->left = NULL;
	T->right = NULL;
	T->label = x;
	return T;
}

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

int LabelB(pok_element* T){
	return T->label;
}

void ChangeLabelB(int x, pok_element* T){
	T->label = x;
}

pok_element* ParentB(int n, pok_element* T){
	if(T->label == n) return NULL;
	if(T->left){
		if(T->left->label == n) return T;
		ParentB(n, T->left);
	}
	if(T->right){
		if(T->right->label == n) return T;
		ParentB(n, T->right);
	}
}

pok_element* LeftChildB(pok_element* T){
	return T->left;
}

pok_element* RightChildB(pok_element* T){
	return T->right;
}

void CreateLeftB(int x, pok_element* T){
	if(T->left) cout << "Cvor vec ima dijete!" << endl;
	else{
		pok_element* novi = new pok_element;
		novi->label = x;
		novi->left = NULL;
		novi->right = NULL;
		T->left = novi;
	}
}

void CreateRightB(int x, pok_element* T){
	if(T->right) cout << "Cvor vec ima dijete!" << endl;
	else{
		pok_element* novi = new pok_element;
		novi->label = x;
		novi->left = NULL;
		novi->right = NULL;
		T->right = novi;
	}
}

void DeleteB(pok_element* n, pok_element* T){
	if(n->left != NULL)
		DeleteB(n->left, T);
	if(n->right != NULL)
		DeleteB(n->right, T);	
	delete n;
}

Initial URL

                                

Initial Description
Implementacija binarnog stabla pomoću pokazivača za kolegij Strukture podataka.

Initial Title
binarno stablo_pokazivac

Initial Tags
podataka

Initial Language
C++