Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Solutions to Tree Data Structure #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Create Postorder_Traversal.cpp
  • Loading branch information
ashaywalke authored Oct 4, 2018
commit ae1b41dc493049d88ed3409e74705b740424395f
21 changes: 21 additions & 0 deletions Tree Data Structure/Postorder_Traversal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*Given a binary tree, return the postorder traversal of its nodes’ values.*/


vector<int> Solution::postorderTraversal(TreeNode* A) {
vector<int> Answer;
stack<TreeNode*> stac;
if(!A)return Answer;
stac.push(A);

while(!stac.empty()){
struct TreeNode * nod = stac.top();
Answer.push_back(nod -> val);
stac.pop();
if(nod -> left) stac.push(nod->left);
if(nod -> right) stac.push(nod->right);

}
reverse(Answer.begin(),Answer.end());
return Answer;

}