Return to Snippet

Revision: 65710
at January 13, 2014 12:44 by AOT_code


Updated 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;
}

Revision: 65709
at January 12, 2014 13:25 by AOT_code


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){
	pok_element* erase = n, * parent = ParentB(n->label, T);
	if(parent->left == n) parent->left = NULL;
	else parent->right = NULL;
	if(n->left) DeleteB(n->left,T);
	else if(n->right) DeleteB(n->right,T);
	delete erase;
}

Initial URL

                                

Initial Description
Implementacija binarnog stabla pomoću funkcija koristeći pokazivače.

Initial Title
binarno_stabo_pokazivac.h

Initial Tags
list

Initial Language
C++