/ Published in: C++
test
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <iostream> #include "binarno_polje.h" using namespace std; int main(){ st_BTREE *tree; st_ELEM elem; int unos; bool dl; int parent; int izbor; do{ cout << "Izbornik:\n0.Ispis\n1.InitT\n2.CreateT\n3.DeleteT\n4.ParentT\n5.LeftChildT\n6.RightChildT\n7.LabelT\n8.RootT\n9.ChangeLabelT\n"; cin >> izbor; switch(izbor){ case 1:{ cout << "Vrijednost korijena?: "; cin >> elem.label; tree = INIT_B(elem.label, tree); break; } case 2:{ cout << "Koliko cvorova unijeti (bez root-a)?: "; cin >> unos; do{ cout << "Parent?: "; cin >> parent; cout << "Label?: "; cin >> elem.label; if(LABEL_B(parent, tree) < elem.label) CREATE_LEFT_B(elem.label, parent, tree); if(LABEL_B(parent, tree) > elem.label) CREATE_RIGHT_B(elem.label, parent, tree); if(LABEL_B(parent, tree) == elem.label) continue; unos--; }while(unos); break; } case 0:{ cout << "INDEKS\tLABEL\tCHILD\tSIBLING\n"; for(int i = 1; i < ARRAY_SIZE; i++){ if(tree->node[i].used == 0)continue; cout << i << "\t"; cout << tree->node[i].label << "\t\n"; } break; } case 3:{ int n; cout << "Koji cvor obrisati (indeks)?: "; cin >> n; DELETE_B(n, tree); break; } case 4:{ int n; cout << "Unesi indeks cvora?: "; cin >> n; cout << "tLABEL\tCHILD\tSIBLING\n"; cout << PARENT_B(n, tree) << "\t"; break; } case 5:{ int n; cout << "Unesi indeks cvora?: "; cin >> n; cout << "tLABEL\tCHILD\tSIBLING\n"; cout << LEFT_CHILD_B(n, tree) << "\t"; break; } case 6:{ int n; cout << "Unesi indeks cvora?: "; cin >> n; cout << "tLABEL\tCHILD\tSIBLING\n"; cout << RIGHT_CHILD_B(n, tree)<< "\t\n"; break; } case 7:{ int n; cout << "Unesi indeks cvora?: "; cin >> n; cout << LABEL_B(n, tree) << "\t"; break; } case 8:{ cout << "tLABEL\tCHILD\tSIBLING\n"; cout << ROOT_B(tree) << "\t"; break; } case 9:{ int x; int n; cout << "Unesi indeks cvora?: "; cin >> n; cout << "Unesi novi label cvora?: "; cin >> x; CHANGE_LABEL_B(x, n, tree); break; } } }while(izbor != 10); }
URL: test