Revision: 38573
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 5, 2011 06:04 by sara
Initial Code
#include <stdlib.h> #define Null NULL typedef int labeltype; typedef struct element { labeltype label; struct element *left,*right,*parrent; }*btree, *node; btree InitB (labeltype x){ btree myBTree; myBTree=(btree)malloc(sizeof(struct element)); myBTree->left=NULL; myBTree->right=NULL; myBTree->parrent=NULL; myBTree->label=x; return myBTree; } node RootB(btree T){ return (node)T; } node ParrentB(node n, btree T){ if(n==T){ printf("Zatrazili ste roditelja korjenskog cvora\n"); return Null; }else{ return n->parrent; } } node LeftChildB(node n, btree T){ if(n->left==NULL){ return Null; }else{ return n->left; } } node RightChildB(node n, btree T){ if(n->right==NULL){ return Null; }else{ return n->right; } } labeltype LabelB(node n, btree T){ return n->label; } void ChangeLabelB(labeltype x, node n, btree T){ n->label=x; } void CreateLeftB(labeltype x, node n, btree T){ node child; if(n->left!=NULL){ printf("Lijevo dijete ovog cvora vec postoji\n"); exit(1); } child=(node)malloc(sizeof(struct element)); child->left=NULL; child->right=NULL; child->parrent=n; n->left=child; child->label=x; } void CreateRightB(labeltype x, node n, btree T){ node child; if(n->right!=NULL){ printf("Desno dijete ovog cvora vec postoji\n"); exit(1); } child=(node)malloc(sizeof(struct element)); child->left=NULL; child->right=NULL; child->parrent=n; n->right=child; child->label=x; } void DeleteBRek(node n, btree T){ if( n == NULL ) return; DeleteBRek(LeftChildB(n, T), T); node parrent; parrent=n->parrent; if(parrent->left==n) parrent->left=NULL; if(parrent->right==n) parrent->right=NULL; free(n); n=parrent; DeleteBRek(RightChildB(n, T), T); } void DeleteB(node n, btree T ){ if(n->parrent==NULL){ printf("Ne mogu obrisati korjen\n"); exit(1); } node parrent; parrent=n->parrent; if(parrent->left==n) parrent->left=NULL; if(parrent->right==n) parrent->right=NULL; DeleteBRek(n, T); }
Initial URL
Initial Description
Initial Title
bstablo_pokazivaci.h
Initial Tags
Initial Language
C++