Return to Snippet

Revision: 38646
at January 6, 2011 04:02 by sanovinic


Initial Code
#ifndef OSTABLO_H_
#define OSTABLO_H_

typedef int node;

struct elem {
     char label[MAX_D];
     node firstchild, nextsibling;
};
struct tr {
     struct elem elements[1000];
     node first;
};
typedef struct tr tree;

tree *InitT(char *x,tree *T){
    T = new tree[M_V_P];
    T->first=0;
    T->elements[0].firstchild=LAMBD;
    T->elements[0].nextsibling=LAMBD;
    strcpy(T->elements[0].label,x);
    return T;
}
node RootT(tree *T){
    return T->first;
}
node NextSiblingT(node n,tree *T){
    return T->elements[n].nextsibling;
}
node FirstChildT(node n,tree *T){
    return T->elements[n].firstchild;
}
bool CreateT(char *x,node n,tree *T){
    static int uk_broj=1;
    if(uk_broj>=M_V_P) return 1;
    if(T->elements[n].firstchild == LAMBD){
         T->elements[n].firstchild = uk_broj;
         strcpy(T->elements[uk_broj].label,x);
         T->elements[uk_broj].firstchild = LAMBD;
         T->elements[uk_broj].nextsibling = LAMBD;
    }
    else{
         node cvor=FirstChildT(n,T);
         while(NextSiblingT(cvor,T)!=LAMBD) cvor = NextSiblingT(cvor,T);
         T->elements[cvor].nextsibling = uk_broj;
         strcpy(T->elements[uk_broj].label,x);
         T->elements[uk_broj].firstchild = LAMBD;
         T->elements[uk_broj].nextsibling = LAMBD;
    }
    uk_broj++;
    return 0;
}
char *LabelT(node n,tree *T){
    return T->elements[n].label;
}
void ChangeLabelT(char *x,node n,tree *T){
    strcpy(T->elements[n].label,x);
}
void DeleteT(node n,tree *T){
     node cvor = FirstChildT(n,T);
     T->elements[n].firstchild=LAMBD;
     while(cvor!=LAMBD){
                         DeleteT(cvor,T); 
                         cvor=NextSiblingT(cvor,T);
                         } 
                         if(T->first==n){
                         return;
                         }
                         else
                         for (int i=0;i<MAX_D;i++){
                         if(T->elements[i].firstchild==n) {
                         node a = T->elements[i].firstchild;
                         T->elements[i].firstchild = T->elements[a].nextsibling;
                         }
                         else if(T->elements[i].nextsibling==n) {
                         node a = T->elements[i].nextsibling;
                         if(a==LAMBD) T->elements[i].nextsibling = LAMBD;
                         T->elements[i].nextsibling = T->elements[a].nextsibling;
                                      }
                                }
                         }


#endif

Initial URL

                                

Initial Description

                                

Initial Title
Datoteka Zaglavlja - „prvo dijete, sljedeći brat“

Initial Tags

                                

Initial Language
C++