/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include<iostream> using namespace std; struct Selement { double oznaka; bool istrosenost; }; struct bin_stablo { Selement *elements[1000]; }; typedef int element; element ParentB(bin_stablo *bin, element n) { return (n/2); }; element LeftChildB(bin_stablo *bin, element n) { return (2*n); } element RightChildB(bin_stablo *bin, element n) { return (2*n+1); } double LabelB(bin_stablo *bin, element n) { return bin->elements[n]->oznaka; } element RootB(bin_stablo *bin) { return 1; } void CreateLeftB(bin_stablo *bin, element n, double x) { if(bin->elements[2*n]->istrosenost == true) { cout <<"Lijevo dijete vec postoji" << endl; exit(0); } else { bin->elements[2*n]->istrosenost = true; bin->elements[2*n]->oznaka =x; } } void CreateRight(bin_stablo *bin, element n, double x) { if(bin->elements[2*n+1]->istrosenost == true) { cout <<"Desno dijete vec postoji " << endl; exit(0); } else { bin->elements[2*n+1]->istrosenost = true; bin->elements[2*n+1]->oznaka = x; } } void Del(bin_stablo *bin, element n) { if(bin->elements[2*n]->istrosenost == true)Del(bin,2*n); if(bin->elements[2*n+1]->istrosenost == true)Del(bin,2*n+1); bin->elements[n]->istrosenost = false; } void Delete(bin_stablo *bin, element n) { if(bin->elements[n]->istrosenost == false) { cout <<"Cvor ne postoji" << endl; exit(0); } else { Del(bin,n); } } void InitN (bin_stablo *bin, element n){ for (int i=0;i<999;i++){ bin->elements[i]->istrosenost=0; } bin->elements[1]->oznaka = n; bin->elements[1]->istrosenost = 1; } int main(){ return 0; }