Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DULJ 100
- typedef int TIP;
- class elem
- {
- public:
- TIP vrij;
- bool used;
- elem()
- {
- used = false;
- }
- }; //class elem
- struct bt
- {
- elem el[DULJ];
- }; //struct bt
- int ParentB(int n, bt T)
- {
- if(!T.el[n].used) return -1;
- if((n % 2) == 0) return (n/2);
- else return((n-1)/2);
- } //int ParentB(int n, bt T)
- int LeftChildB(int n, bt T)
- {
- if(!T.el[n].used) return -1;
- int r = n * 2;
- if(r > DULJ || !T.el[r].used) return -1;
- else return r;
- } //int LeftChildB(int n, bt T)
- int RightChildB(int n, bt T)
- {
- if(!T.el[n].used) return -1;
- int r = n * 2 + 1;
- if(r >= DULJ || !T.el[r].used) return -1;
- else return r;
- } //int RightChildB(int n, bt T)
- TIP LabelB(int n, bt T)
- {
- if(!T.el[n].used) return -1;
- else return T.el[n].vrij;
- } //int LabelB(int n, bt T)
- int ChangeLabelB(TIP x, int n, bt &T)
- {
- if(!T.el[n].used) return -1;
- else T.el[n].vrij = x;
- return 0;
- } //int ChangeLabelB(int x, int n, bt &T)
- int RootB(bt T)
- {
- if(!T.el[1].used) return -1;
- else return 1;
- } //int RootB(bt T)
- int CreateLeftB(TIP x, int n, bt &T)
- {
- if(!T.el[n].used) return -1;
- int r = n * 2;
- if(T.el[r].used || r >= DULJ) return -1;
- T.el[r].used = true;
- T.el[r].vrij = x;
- return 0;
- } //int CreateLeftB(int x, int n, bt &T)
- int CreateRightB(TIP x, int n, bt &T)
- {
- if(!T.el[n].used) return -1;
- int r = (n * 2) + 1;
- if(T.el[r].used || r >= DULJ) return -1;
- T.el[r].used = true;
- T.el[r].vrij = x;
- return 0;
- } //int CreateRightB(int x, int n, bt &T)
- void DeleteB(int n, bt &T)
- {
- if(n == -1) return;
- if(!T.el[n].used) return;
- DeleteB(LeftChildB(n, T), T);
- DeleteB(RightChildB(n, T), T);
- T.el[n].used = false;
- } //int DeleteB(int n, bt &T)
- void InitB(TIP x, bt &T)
- {
- if(T.el[1].used) DeleteB(RootB(T), T);
- T.el[1].used = true;
- T.el[1].vrij = x;
- } //void InitB(int x, bt &T)
Add Comment
Please, Sign In to add comment