Revision: 38701
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 6, 2011 07:49 by dafilipaj
Initial Code
struct element{ int label; int koristeno; }; struct bt{ element elements[10000]; }; typedef int cvor; bt* InitB(int x, bt* T){ if(T) delete T; T = new bt; for(int i = 0; i < 10000; i++) T->elements[i].koristeno = 0; T->elements[1].label = x; T->elements[1].koristeno = 1; return T; }//initB void CreateLeftB(int x, cvor n, bt* T){ if(T->elements[n].koristeno == 0 || T->elements[2*n].koristeno == 1) { cout << "Greska" << endl << endl; return; } T->elements[2*n].koristeno = 1; T->elements[2*n].label = x; }//CreateLeftB void CreateRightB(int x, cvor n, bt* T){ if(T->elements[n].koristeno == 0 || T->elements[2*n+1].koristeno == 1){ cout << "Greska" << endl << endl; return; } T->elements[2*n+1].koristeno = 1; T->elements[2*n+1].label = x; }//CreateRightB cvor LeftChildB(cvor n, bt* T){ if(T->elements[n].koristeno == 0) return 0; if(T->elements[2*n].koristeno == 1) return 2*n; else return 0; }//LeftCildB cvor RightChildB(cvor n, bt* T){ if(T->elements[n].koristeno == 0) return 0; if(T->elements[2*n+1].koristeno == 1) return 2*n+1; else return 0; }//RightCildB cvor ParentB(cvor n, bt* T){ if(n == 1) return 0; if(n%2) n--; return n/2; }//ParentB int LabelB(cvor n, bt* T){ return T->elements[n].label; }//LabelB void ChangeLabelB(int x, cvor n, bt* T){ if(T->elements[n].koristeno == 0) return; T->elements[n].label = x; }//ChangeLabelB cvor RootB(bt* T){ if(T->elements[1].koristeno == 0) return 0; return 1; }//RootB void DeleteB(cvor n, bt* T){ T->elements[n].koristeno = 0; if (LeftChildB(n, T)) DeleteB(LeftChildB(n, T), T); if (RightChildB(n, T)) DeleteB(RightChildB(n, T), T); }//DeleteB
Initial URL
Initial Description
Initial Title
bstablo_polje.h
Initial Tags
Initial Language
C++