Revision: 38693
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 6, 2011 06:57 by mazorkovi
Initial Code
#ifndef OSTABLO_H_
#define OSTABLO_H_
typedef int nodao;
struct elem {
char label[MAX_DULJINA];
nodao firstchild, nextsibling;
};
struct tr {
struct elem elements[1000];
nodao first;
};
typedef struct tr tree;
tree *InitT(char *x,tree *T){
T = new tree[MAX_VELICINA_POLJA];
T->first=0;
T->elements[0].firstchild=LAMBDAO;
T->elements[0].nextsibling=LAMBDAO;
strcpy(T->elements[0].label,x);
return T;
}
nodao RootT(tree *T){
return T->first;
}
nodao NextSiblingT(nodao n,tree *T){
return T->elements[n].nextsibling;
}
nodao FirstChildT(nodao n,tree *T){
return T->elements[n].firstchild;
}
bool CreateT(char *x,nodao n,tree *T){
static int uk_broj=1;
if(uk_broj>=MAX_VELICINA_POLJA) return 1;
if(T->elements[n].firstchild == LAMBDAO){
T->elements[n].firstchild = uk_broj;
strcpy(T->elements[uk_broj].label,x);
T->elements[uk_broj].firstchild = LAMBDAO;
T->elements[uk_broj].nextsibling = LAMBDAO;
}
else{
nodao cvor=FirstChildT(n,T);
while(NextSiblingT(cvor,T)!=LAMBDAO) cvor = NextSiblingT(cvor,T);
T->elements[cvor].nextsibling = uk_broj;
strcpy(T->elements[uk_broj].label,x);
T->elements[uk_broj].firstchild = LAMBDAO;
T->elements[uk_broj].nextsibling = LAMBDAO;
}
uk_broj++;
return 0;
}
char *LabelT(nodao n,tree *T){
return T->elements[n].label;
}
void ChangeLabelT(char *x,nodao n,tree *T){
strcpy(T->elements[n].label,x);
}
void DeleteT(nodao n,tree *T){
nodao cvor = FirstChildT(n,T);
T->elements[n].firstchild=LAMBDAO;
while(cvor!=LAMBDAO){
DeleteT(cvor,T);
cvor=NextSiblingT(cvor,T);
}
if(T->first==n){
return;
}
else
for (int i=0;i<MAX_DULJINA;i++){
if(T->elements[i].firstchild==n) {
nodao a = T->elements[i].firstchild;
T->elements[i].firstchild = T->elements[a].nextsibling;
}
else if(T->elements[i].nextsibling==n) {
nodao a = T->elements[i].nextsibling;
if(a==LAMBDAO) T->elements[i].nextsibling = LAMBDAO;
T->elements[i].nextsibling = T->elements[a].nextsibling;
}
}
}
#endif
Initial URL
Initial Description
Initial Title
Implementacija ostablo
Initial Tags
Initial Language
C++