# Posted By

marfioren on 01/19/15

# Statistics

Viewed 356 times
Favorited by 0 user(s)

# binarno stablo-pokazivaci

/ Published in: C++
Save to your folder(s)

binarno stablo-pokazivaci

Copy this code and paste it in your HTML
`struct belement {	int v;	belement *lijevo;	belement *desno;}; typedef belement* binStablo;typedef belement* binNode; binStablo InitB(int x, binStablo t) {	t = new belement;	t->v = x;	t->lijevo = 0;	t->desno = 0; 	return t;} binNode RootB(binStablo t) {	return t;} binNode ParentB(binNode n, binStablo t) {	binNode r = 0; 	if(n==RootB(t))return 0;	if(t->lijevo==n || t->desno==n)		return t; 	if(t->lijevo)		r=ParentB(n, t->lijevo);	if(r)return r;	if(t->desno)		r=ParentB(n, t->desno);	if(r)return r;} binNode LeftChildB(binNode n, binStablo t) { return n->lijevo;}binNode RightChildB(binNode n, binStablo t) { return n->desno;} int LabelB(binNode n, binStablo t) {	return n->v;}void ChangeLabelB(int x, binNode n, binStablo t) {	if(n!=0)		n->v = x;} void CreateLeftB(int x, binNode n, binStablo t) {	binNode nel = new belement; 	nel->v = x; nel->lijevo = 0; nel->desno = 0;	n->lijevo = nel;} void CreateRightB(int x, binNode n, binStablo t) {	binNode nel = new belement; 	nel->v = x; nel->lijevo = 0; nel->desno = 0;	n->desno = nel;} void DeleteB(binNode n, binStablo t) {	if(t!=0) {		if(ParentB(n, t)==0) return; 		binNode r = ParentB(n, t);		if(r->lijevo==n)r->lijevo=0;		if(r->desno==n)r->desno=0; 		DeleteB(n, 0);	}	else {		if(n->lijevo!=0)DeleteB(n->lijevo, 0);		if(n->desno!=0)DeleteB(n->desno, 0); 		delete n;	}}`

## Comments

Subscribe to comments

You need to login to post a comment.