Revision: 38574
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 5, 2011 06:16 by mateja2802
Initial Code
#define N 10000
struct element {
char labela[20];
int used;
};
struct bt {
element polje[N];
};
int ParentB (int p, bt* stablo) {
if (stablo->polje[p].used == 0) return -1;
if (p & 1) return (p - 1) / 2;
else return p / 2;}
int RootB (bt* stablo) {
if (stablo->polje[1].used) return 1;
else return 0;}
int LeftChildB (int p, bt* stablo) {
if ((stablo->polje[p * 2]).used) return p * 2;
return -1;}
int RightChildB (int p, bt* stablo) {
if ((stablo->polje[p * 2 + 1]).used) return p * 2 + 1;
return -1;}
void DeleteB (int p, bt* stablo) {
if (stablo->polje[p*2].used)
DeleteB(p*2, stablo);
stablo->polje[p].used ^= stablo->polje[p].used;
if (stablo->polje[p*2+1].used)
DeleteB(p*2+1, stablo);}
void InitB (char* label, bt* stablo) {
if ((stablo->polje[1]).used) {
DeleteB(1, stablo);
(stablo->polje[1]).used = 1;
strcpy((stablo->polje[1].labela), label);
}
else {
(stablo->polje[1]).used = 1;
strcpy((stablo->polje[1].labela), label);}}
char* LabelB(int p, bt* stablo) {
if (stablo->polje[p].used) return stablo->polje[p].labela;
return 0;}
void ChangeLabelB (char* label, int p, bt* stablo) {
if (stablo->polje[p].used) strcpy(stablo->polje[p].labela, label);}
void CreateLeftB (char* label, int p, bt* stablo) {
if (! stablo->polje[p*2].used && stablo->polje[p].used) {
stablo->polje[p*2].used = 1;
strcpy(stablo->polje[p*2].labela, label);}}
void CreateRightB (char* label, int p, bt* stablo) {
if (! stablo->polje[p*2+1].used && stablo->polje[p].used) {
stablo->polje[p*2+1].used = 1;
strcpy(stablo->polje[p*2+1].labela, label);}}1
Initial URL
Initial Description
Initial Title
Implementacija binarnog stabla pomoću polja
Initial Tags
Initial Language
C++