Return to Snippet

Revision: 38713
at January 6, 2011 08:14 by masrnec


Initial Code
#ifndef OSTABLO_H_
#define OSTABLO_H_

typedef int node;

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

tree *InitT(char *x,tree *T){
    T = new tree[MAX_VELICINA_POLJA];
    T->first=0;
    T->elements[0].firstchild=IZLAZ;
    T->elements[0].nextsibling=IZLAZ;
    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>=MAX_VELICINA_POLJA) return 1;
    if(T->elements[n].firstchild == IZLAZ){
         T->elements[n].firstchild = uk_broj;
         strcpy(T->elements[uk_broj].label,x);
         T->elements[uk_broj].firstchild = IZLAZ;
         T->elements[uk_broj].nextsibling = IZLAZ;
    }
    else{
         node cvor=FirstChildT(n,T);
         while(NextSiblingT(cvor,T)!=IZLAZ) cvor = NextSiblingT(cvor,T);
         T->elements[cvor].nextsibling = uk_broj;
         strcpy(T->elements[uk_broj].label,x);
         T->elements[uk_broj].firstchild = IZLAZ;
         T->elements[uk_broj].nextsibling = IZLAZ;
    }
    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=IZLAZ;
    while(cvor!=IZLAZ){
        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) {
               node a = T->elements[i].firstchild;
               
           }
       }
}
#endif

Initial URL

                                

Initial Description

                                

Initial Title
opcenito stablo - implementacija

Initial Tags

                                

Initial Language
C++