Return to Snippet

Revision: 68467
at January 19, 2015 04:05 by sargaxon


Initial Code
#include <iostream>
using namespace std;

struct elem {
    int label, firstchild, nextsibling;
};
     
struct t {
    elem elementi[10000];
    int first;
};
     
t stablo;     
int FirstChildT (int n, t stablo) {
    return stablo.elementi[n].firstchild;
    }

int NextSiblingT (int n, t stablo) {
    return stablo.elementi[n].nextsibling;
}
     
int LabelT (int n, t stablo) {
    return stablo.elementi[n].label;
}
     
int ParentT (int n, t stablo) {
    for (int i=1; i<10000; i++) {
    if (FirstChildT(i, stablo)==n)
    return i;
    if (NextSiblingT(i, stablo)==n)
    return ParentT(i, stablo);
       }
    return -1;
}
     
int RootT (t stablo) {
    return stablo.first;
}
     
int CreateT (int x, int n, t &stablo) {
    int pom = 1;
    while (LabelT(pom, stablo)!=-1)
           pom++;
    stablo.elementi[pom].label = x;
    stablo.elementi[pom].firstchild = -1;
    stablo.elementi[pom].nextsibling = -1;
    if (stablo.elementi[n].firstchild != -1) {
           n = FirstChildT(n, stablo);
           while (NextSiblingT(n, stablo)!=-1)
           n = NextSiblingT(n, stablo);
           stablo.elementi[n].nextsibling = pom;
            }
    else stablo.elementi[n].firstchild = pom;
    return pom;
}
     
void ChangeLabelT (int x, int n, t &stablo) {
    stablo.elementi[n].label = x;
}
     
void DeleteT (int n, t &stablo) {
    int pom;
    if (FirstChildT(n, stablo)!=-1) {
           pom = FirstChildT(n, stablo);
           DeleteT(pom, stablo);
           while (NextSiblingT(pom, stablo)!=-1) {
               pom = NextSiblingT(pom, stablo);
               DeleteT(pom, stablo);
                  }
       }
    stablo.elementi[n].label = -1;
    if (n != RootT(stablo) && FirstChildT(ParentT(n,stablo), stablo)==n)
           stablo.elementi[ParentT(n, stablo)].firstchild = NextSiblingT(n, stablo);
    else if (n != RootT(stablo)) {
           pom = FirstChildT(ParentT(n,stablo), stablo);
    while (NextSiblingT(pom, stablo) != n)
           pom = NextSiblingT(pom, stablo);
    stablo.elementi[pom].nextsibling = NextSiblingT(n, stablo);
        }
}
     
void InitT (int x, t &stablo) {
    stablo.first = 1;
    stablo.elementi[1].label = x;
    stablo.elementi[1].firstchild = -1;
    stablo.elementi[1].nextsibling = -1;
    for (int i=2; i<10000; i++) {
          stablo.elementi[i].label = -1;
          stablo.elementi[i].firstchild = -1;
          stablo.elementi[i].nextsibling = -1;
          }
}

Initial URL


Initial Description
strukture podataka

Initial Title
prvo dijete sljedeci brat

Initial Tags


Initial Language
C++