Revision: 38427
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 2, 2011 08:14 by ivamileti
Initial Code
#include<iostream> using namespace std; struct Selement { double oznaka; Selement *lijevo, *desno; }; typedef Selement *element; element LeftChildB(Selement *bin, Selement *n) { return n->lijevo; } element RightChildB(Selement *bin, Selement *n) { return n->desno; } double LabelB(Selement *bin, Selement *n) { return n->oznaka; } element RootB(Selement *bin) { return(bin); } element ParentB(Selement *bin, Selement *n) { element t1; bool OK; t1 = RootB(bin); if(t1==n) { cout <<"Cvor nema roditelja" << endl; exit(0); } } void CreateLeftB(Selement *bin, Selement *n, double x) { element l,n1; if(n->lijevo!=NULL) { cout <<"Cvor vec ima dijete" << endl; exit(0); } else { l = (Selement*)malloc(sizeof(Selement)); l->lijevo = NULL; l->desno = NULL; l->oznaka = x; n->lijevo = l; } } void CreateRightB(Selement *bin, Selement *n, double x) { element r; if(n->desno != NULL){ cout <<"Cvor vec ima desno dijete" << endl; exit(0); } else { r = (Selement*)malloc(sizeof(Selement)); r->lijevo = NULL; r->desno = NULL; r->oznaka = x; n->desno = r; } } void Del(Selement *bin, Selement *n) { if(n->lijevo != NULL)Del(bin,LeftChildB(bin,n)); if(n->desno != NULL) Del(bin,RightChildB(bin,n)); free(n); } void DeleteB(Selement *bin, Selement *n) { element t1; t1 = ParentB(bin,n); if(LeftChildB(bin,t1)==n) { t1->lijevo = NULL; } else { t1->desno = NULL; } Del(bin,n); } void InitB (int x, Selement *n){ n->oznaka=x; n->desno=NULL; n->lijevo=NULL; }
Initial URL
Initial Description
Initial Title
Implementacija binarnog stabla pomoću pokazivaca
Initial Tags
Initial Language
C++