Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define MAXB 1000
- #define MAXS 1000
- typedef int nodetypeb;
- #include "btree.h"
- typedef nodeb elementtypes;
- #include "stack.h"
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- void Process(btree &B,nodeb n) {
- std::cout << LabelB(B,n) << " ";
- }
- void PoO(btree &B, nodeb n) {
- if (LeftChildB(B,n) != lambdab)
- PoO(B,LeftChildB(B,n));
- if (RightChildB(B,n) != lambdab)
- PoO(B,RightChildB(B,n));
- Process(B,n);
- }
- void Postorder(btree &B) {
- PoO(B,RootB(B));
- }
- void postOrder(btree &B)
- {
- stack S;
- InitS(S);
- bool T
- nodeb n = RootB(B);
- if (RootB(B) == NULL)
- return;
- do
- {
- while ()
- {
- if (RightChildB(B,n))
- PushS(S, RightChildB(B,n));
- PushS(S, RootB(B));
- n = RightChildB(B,n);
- T = true;
- }
- }
- n = PopS(S);
- if (RightChildB(B,n) && TopS(S) == RightChildB(B,n))
- {
- PopS(S);
- PushS(S, n);
- n = RightChildB(B,n);
- }
- else
- {
- std::cout << " " << LabelB(B,n) << std::endl;
- n = NULL;
- }
- } while (!IsEmptyS(S));
- }
- int main () {
- btree B;
- int br;
- int m;
- char izbor;
- int broj;
- cout << "broj cvorova: ";
- cin >> br;
- int i = 0;
- cout << "Root: ";
- cin >> m;
- InitB(B,m);
- nodeb n = RootB(B);
- while(i<br){
- cout << "Lijevo(L) Desno(D) Gore(U)" << endl;
- cin >> izbor;
- if(izbor == 'L'){
- cin >> broj;
- CreateLeftChildB(B,n,broj);
- n = LeftChildB(B,n);
- i++;}
- if(izbor == 'D'){
- cin >> broj;
- CreateRightChildB(B,n,broj);
- n = RightChildB(B,n);
- i++;}
- if(izbor == 'U'){
- n = ParentB(B,n);}
- }
- postOrder(B);
- std::cout << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement