Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BinTraversal
//Title of this code #include <iostream> #include <list> using namespace std; struct BinTree { int data; BinTree *left; BinTree *right; BinTree(int d, BinTree* l, BinTree* r): data(d), left(l), right(r) {} }; void post_order_traversal(BinTree *root) { list<BinTree*> stack; bool isRight = false; //stack.push_front(root); BinTree *current = root; while (true) { if (current->left) { stack.push_front(current); current = current->left; continue; } else { cout << current->data; current = stack.front(); stack.pop_front(); if (current.right) current } } } int main() { BinTree *j = new BinTree(9, NULL, NULL); BinTree *h = new BinTree(8, NULL, NULL); BinTree *g = new BinTree(7, NULL, NULL); BinTree *f = new BinTree(6, j, h); BinTree *e = new BinTree(5, NULL, NULL); BinTree *d = new BinTree(4, NULL, NULL); BinTree *c = new BinTree(3, f, g); BinTree *b = new BinTree(2, d, e); BinTree *a = new BinTree(1, b, c); post_order_traversal(a); cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
VolAreObject
TypeSizeTest
Dijkstra
string iteration performance
point to a rvalue
new
precision and fixed point notation
Lotto random number game {modify}
ADVENTURE CODE CSCI40
CPP - Arrays - Ex.3