Revision: 68503
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 19, 2015 05:55 by ksimunovic
Initial Code
#include <iostream>
using namespace std;
char lab[50];
bool alocirano = false;
struct el
{
char naziv[50];
bool last;
};
struct sp
{
el elementi[1000];
};
void InitB(char naziv[50], sp *stablo)
{
for(int i=0;i<999;i++)
stablo->elementi[i].last = 0;
stablo->elementi[1].last = 1;
strcpy(stablo->elementi[1].naziv, naziv);
alocirano = true;
}
bool ParentB(int n, sp *stablo)
{
if(n==1)
{
cout << "NULL cvor" << endl;
return 0;
}
strcpy(lab, stablo->elementi[n/2].naziv);
return 1;
}
bool CreateLeftB(char naziv[50], int n, sp *stablo)
{
if(stablo->elementi[n].last = 0)
{
cout << "Cvor ne postoji!" << endl;
return 0;
}
if(stablo->elementi[n*2].last == 1)
{
cout << "Pogreska!" << endl;
return 0;
}
stablo->elementi[n*2].last = 1;
strcpy(stablo->elementi[n*2].naziv, naziv);
return 1;
}
bool CreateRightB(char naziv[50], int n, sp *stablo)
{
if(stablo->elementi[n].last = 0)
{
cout << "Cvor ne postoji!" << endl;
return 0;
}
if(stablo->elementi[n*2+1].last==1)
{
cout << "Pogreska!" << endl;
return 0;
}
stablo->elementi[n*2+1].last = 1;
strcpy(stablo->elementi[n*2+1].naziv, naziv);
return 1;
}
bool DeleteB(int n, sp *stablo)
{
stablo->elementi[n].last = 0;
stablo->elementi[n].naziv[0] = '\0';
int j=n*2,k=n*2+1;
if(j < 1000)
DeleteB(j, stablo);
if(k < 1000)
DeleteB(k, stablo);
return 0;
}
void ChangeLabelB(int n, sp *stablo)
{
strcpy(lab, stablo->elementi[n].naziv);
}
void ChangeLabelT(char naziv[50], int n, sp *stablo)
{
strcpy(stablo->elementi[n].naziv, naziv);
}
bool RootB(sp*stablo)
{
if(!alocirano)
{
cout << "Stablo je prazno!" << endl;
return 0;
}
strcpy(lab, stablo->elementi[1].naziv);
return 1;
}
bool LeftChildB(int n, sp *stablo)
{
if(stablo->elementi[n*2].last == 0)
{
cout << "Nema lijevog djeteta!" << endl;
return 0;
}
strcpy(lab, stablo->elementi[n*2].naziv);
return 1;
}
bool RightChildB(int n, sp *stablo)
{
if(stablo->elementi[n*2+1].last == 0)
{
cout << "Nema desnog djeteta!" << endl;
return 0;
}
strcpy(lab, stablo->elementi[n*2+1].naziv);
return 0;
}
Initial URL
Initial Description
bstablo_polje.h
Initial Title
bstablo_polje.h
Initial Tags
Initial Language
C++