Revision: 65691
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 12, 2014 00:31 by mvracan
Initial Code
#include<iostream>
using namespace std;
struct node{
char label;
int child,brother;
};
struct tree{
node polje[10000];
int root;
};
tree *InitT(int k,tree *T){
T = new tree;
for(int i=0;i<10000;i++){
T->polje[i].label = ' ';
T->polje[i].child = -1;
T->polje[i].brother = -1;
}
T->polje[k].label = 'A';
T->root = k;
return T;
}
void ChangeLabelT(char x,int n,tree *T){
T->polje[n].label = x;
}
int RootT(tree *T){
return T->root;
}
char LabelT(int n,tree *T){
if(T->polje[n].label==' ') cout << "Cvor " << n << " ne postoji u stablu!" << endl;
return T->polje[n].label;
}
void CreateT(int x,int n,tree *T){
if(T->polje[n].label==' ') cout << "Cvor " << n << " ne postoji u stablu!" << endl;
else{
if(T->polje[n].child==-1) T->polje[n].child = x;
else if(T->polje[T->polje[n].child].brother==-1) T->polje[T->polje[n].child].brother = x;
else{
n = T->polje[n].child;
while(T->polje[n].brother!=-1) n = T->polje[n].brother;
T->polje[n].brother = x;
}
T->polje[x].label = T->polje[n].label+1;
T->polje[x].child = -1;
T->polje[x].brother = -1;
}
}
int FirstChildT(int n,tree *T){
return T->polje[n].child;
}
int NextSiblingT(int n,tree *T){
return T->polje[n].brother;
}
int ParentT(int n,tree *T){
for(int i=0;i<10000;i++){
if(T->polje[i].child==n) return i;
if(T->polje[i].brother==n) return ParentT(i,T);
}
}
tree *DeleteT(int n,tree *T){
if(n==RootT(T)){
T = InitT(-1,T);
return T;
}
else{
if(T->polje[n].child!=-1) DeleteT(T->polje[n].child,T);
if(T->polje[n].brother!=-1) DeleteT(T->polje[n].brother,T);
T->polje[n].child = -1;
T->polje[n].brother = -1;
T->polje[n].label = ' ';
if(T->polje[ParentT(n,T)].brother!=-1) T->polje[ParentT(n,T)].child = T->polje[n].brother;
else T->polje[ParentT(n,T)].child = -1;
}
}
Initial URL
Initial Description
zadatak4
Initial Title
opcenito stablo.h
Initial Tags
Initial Language
C++