/ Published in: C++
Here is test program using all functions in my headers.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <iostream> #include <cmath> #include "polje.h" #include "pokazivac.h" /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace stablo_polje; using namespace std; template<typename labeltype> void napuni_stablo(int cvor, int dubina, bt<labeltype>&stablo) { if(dubina<=0) return; cout << "Cvor: " << cvor << ", labela: " << LabelB(cvor,stablo) << endl; CreateLeftB((float)dubina,cvor,stablo); CreateRightB((float)dubina,cvor,stablo); napuni_stablo(LeftChildB(cvor,stablo),dubina-1,stablo); napuni_stablo(RightChildB(cvor,stablo),dubina-1,stablo); } int main() { bt <float>stablo; InitB(50.0f,stablo); napuni_stablo(1,5,stablo); cout << "Stablo kreirano.\n"; int argnode=6; cout << "Parent (" << argnode << ")=" << ParentB(argnode,stablo) << endl; cout << "LeftChild (" << argnode << ")=" << LeftChildB(argnode,stablo) << endl; cout << "RightChild (" << argnode << ")=" << RightChildB(argnode,stablo) << endl; cout << "Labela (" << argnode << ")=" << LabelB(argnode,stablo) << endl; ChangeLabelB(11.0f,argnode,stablo); cout << "Promjenjena labela (" << argnode << ")=" << LabelB(argnode,stablo) << endl; cout << "Root: " << RootB(stablo) << endl; argnode=10; cout << "LeftChild (" << argnode << ")=" << LeftChildB(argnode,stablo) << endl; if(CreateLeftB(100.0f,argnode,stablo)) cout << "Kreirano lijevo djete na " << argnode << ".\n"; else cout << "Nije uspjelo kreiranje lijevog djeteta na " << argnode << ".\n"; cout << "LeftChild (" << argnode << ")=" << LeftChildB(argnode,stablo) << endl; cout << "RightChild (" << argnode << ")=" << RightChildB(argnode,stablo) << endl; if(CreateRightB(100.0f,argnode,stablo)) cout << "Kreirano desno djete na " << argnode << ".\n"; else cout << "Nije uspjelo kreiranje desnog djeteta na " << argnode << ".\n"; cout << "RightChild (" << argnode << ")=" << RightChildB(argnode,stablo) << endl; cout << "Labela djece: " << LabelB(LeftChildB(argnode,stablo),stablo) << ", "; cout << LabelB(RightChildB(argnode,stablo),stablo) << ".\n"; cout << "Brisanje 4...\n"; argnode=4; DeleteB(argnode,stablo); cout << "Labela djece cetvorke: " << LabelB(LeftChildB(argnode,stablo),stablo) << ", "; cout << LabelB(RightChildB(argnode,stablo),stablo) << ".\n"; cout << "Inicijalizacija..." << endl; InitB(50.0f,stablo); cout << "Root label: " << LabelB(RootB(stablo),stablo) << endl; argnode=1; cout << "Labela djece korjena: " << LabelB(LeftChildB(argnode,stablo),stablo) << ", "; cout << LabelB(RightChildB(argnode,stablo),stablo) << ".\n"; system("PAUSE"); return 0; }