Return to Snippet

Revision: 65698
at January 12, 2014 04:11 by mvracan


Initial Code
#include<iostream>
using namespace std;
 
struct anode{
    int label;
    bool used;
};
 
struct atree{
    anode polje[1000];
};
 
atree *aInitB(int x,atree *T){
    T = new atree;
    for(int i=0;i<1000;i++){
            T->polje[i].used = false;
            T->polje[i].label = -1;
            }
    T->polje[1].label = x;
    T->polje[1].used = true;
    return T;
    }
 
int aLabelB(int n,atree *T){
    return T->polje[n].label;
    }
 
void aChangeLabelB(int x,int n,atree *T){
    T->polje[n].label = x;
    }
 
int aRootB(atree *T){
    return T->polje[1].label;
    }
 
int aLeftChildB(int n,atree *T){
    return 2*n;
    }
 
int aRightChildB(int n,atree *T){
    return 2*n+1;
    }
 
int aParentB(int n,atree *T){
    if(T->polje[1].label==n) return -1;
    if(n%2) return n/2+1;
    else return n/2;
    }
 
void aCreateLeftB(int x,int n,atree *T){
    if(T->polje[2*n].used) cout << "Lijevo dijete ve����¯�¿�½ postoji!" << endl;
    else{
        T->polje[2*n].label = x;
        T->polje[2*n].used = true;
        }
    }
 
void aCreateRightB(int x,int n,atree *T){
    if(T->polje[2*n+1].used) cout << "Desno dijete ve����¯�¿�½ postoji!" << endl;
    else{
        T->polje[2*n+1].label = x;
        T->polje[2*n+1].used = true;
        }
    }
 
void aDeleteB(int n,atree *T){
    if(T->polje[aLeftChildB(n,T)].used) aDeleteB(2*n,T);
    if(T->polje[aRightChildB(n,T)].used) aDeleteB(2*n-1,T);
    T->polje[n].label = -1;
    T->polje[n].used = false;
    }

Initial URL

                                

Initial Description
zadatak4

Initial Title
binarno stablo pomocu polja.h

Initial Tags

                                

Initial Language
C++