Revision: 39143
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 14, 2011 01:42 by sejstefic
Initial Code
#include<iostream> using namespace std; struct elem { int label; int used; }; struct bintree { elem elements[1000]; }; typedef struct bintree *bs; typedef int node; node ParentB(node c,bintree *bs) { if (c=1) return(-1); else return((int)c/2); } node LeftChildB(node c,bintree *bs) { if (bs->elements[2*c].used) return(2*c); else { return(-1); } } node RightChildB(node c,bintree *bs) { if (bs->elements[2*c+1].used) return(2*c+1); else { return(-1); } } node RootB(bintree *bs) { return(1); } void DeleteB(node c,bintree *bs) { if(bs->elements[(c*2)+1].used==true){ DeleteB((c*2)+1, bs); } if(bs->elements[(c*2)+2].used==true){ DeleteB((c*2)+2, bs); } bs->elements[c].used=false; } typedef int labeltype; labeltype LabelB(node c,bintree *bs) { return(bs->elements[c].label); } void ChangeLabelB(labeltype x, node c,bintree *bs) { if (bs->elements[c].used) bs->elements[c].label = x; else { cout<<"Trazeni cvor u stablu nema vrijednost."<<endl; } } void CreateLeftB(labeltype x,node c,bintree *bs) { if (bs->elements[2*c].used) { cout<<"Cvor ima lijevo dijete"<<endl; } else { bs->elements[2*c].used = -1; bs->elements[2*c].label = x; } } void CreateRightB(labeltype x,node c,bintree *bs) { if (bs->elements[2*c+1].used) { cout<<"Cvor ima desno dijete"<<endl; } else { bs->elements[2*c+1].used = -1; bs->elements[2*c+1].label = x; } } void InitB(node n,bintree *bs) { int i; for (i=0;i<=999;i++) bs->elements[i].label=-1; bs->elements[1].label=n; bs->elements[1].used=-1; }
Initial URL
Initial Description
Initial Title
Implementacija binarnog stabla pomocu polja
Initial Tags
Initial Language
C++