Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #define MAXS 1000
- typedef int nodetypeb;
- typedef int elementtypes;
- typedef int elementtype;
- #include "abtree.h"
- #include "astack.h"
- using namespace std;
- int main(){
- stack S;
- btree B;
- nodetypeb v;
- char odabir;
- int n;
- nodeb cvor;
- cout<<"Koliko cvorova: "<<endl;
- cin>>n;
- cout<<"Korijen: "<<endl;
- cin>>v;
- InitB(B,v);
- InitS(S);
- cvor=RootB(B);
- while(n!=0){
- cout<<"Trenutna lokacija: "<<cvor<<" Oznaka: "<<LabelB(B,cvor)<<endl;
- cout<<"Dodavanje dijeteta L-D"<<endl;
- cout<<"Prelazak dijeteta F-G"<<endl;
- cout<<"Povratak na roditelja P\n"<<endl;
- cin>>odabir;
- if(odabir=='D' || odabir=='L') n--;
- if(odabir=='L'){
- cout<<"Unesite oznaku: "; cin>>v;
- CreateLeftChildB(B,cvor,v);
- }
- else if(odabir=='D'){
- cout<<"Unesite oznaku: "; cin>>v;
- CreateRightChildB(B,cvor,v);
- }
- else if(odabir=='F'){
- cvor=LeftChildB(B,cvor);
- }
- else if(odabir=='G'){
- cvor=RightChildB(B,cvor);
- }
- else if(odabir=='P'){
- cvor=ParentB(B,cvor);
- }
- }
- cvor=RootB(B);
- stack ZaPosjetiti;
- stack Posjeceni;
- InitS(ZaPosjetiti);
- InitS(Posjeceni);
- PushS(ZaPosjetiti, elementtypes(cvor));
- while(IsEmptyS(ZaPosjetiti)!=true){
- int trenutni = TopS(ZaPosjetiti);
- if(RightChildB(B, trenutni)!=-1 ||LeftChildB(B, trenutni)!=-1){
- if(TopS(Posjeceni) != trenutni){
- PushS(Posjeceni, trenutni);
- }
- PopS(Posjeceni);
- }
- cout<<trenutni<<", "<<endl;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement