L10. iterative Inorder Traversal in Binary Tree | C++ | Java | Stack

preview_player
Показать описание

Find DSA, LLD, OOPs, Core Subjects, 1000+ Premium Questions company wise, Aptitude, SQL, AI doubt support and many other features that will help you to stay focussed inside one platform under one affordable subscription. Have a hassle free one stop solution for up-skilling and preparing.

Checkout the problem link 👇🏼
iterative Inorder Traversal in Binary Tree | C++ | Java | Stack

Рекомендации по теме
Комментарии
Автор

Hi, hope you are well.


Find DSA, LLD, OOPs, Core Subjects, 1000+ Premium Questions company wise, Aptitude, SQL and many other time saving features under one affordable subscription. Have a hassle free one stop solution for up-skilling and preparing yourself.


takeUforward
Автор

I bought a course from Coding Ninjas, I spent about 6000 on that and they have not even talked about iterative ways in the tree part.
Thanks Striver bhai for making these high quality videos for free.

pushkarraja
Автор

Felt bad... your work deserves more likes ...those who watched it, please like this..so that it will improves sir's interest

deepaksarvepalli
Автор

for skip promotion go to 0:43
code explanation at 8:49

PrashantSingh-jyzp
Автор

I first like the video then starts watching 🤩....! Because I know your videos are always amazing. Thank you so much for such a amazing series.

allinonep.
Автор

Very clearly explained! 👏 Just one thing, we can use root variable itself, instead of declaring 'node'. It still works! ( however no memory usage improvement on leetcode)

shivangisrivastava
Автор

Alternative :
```cpp
void inorder(Node* root) {
if (root == NULL) return;
stack<Node*> st;
Node* current = root;
while (current != NULL || !st.empty()) {
while (current != NULL) {
st.push(current);
current = current->left;
}
current = st.top();
st.pop();
cout << current->data << " ";
current = current->right;
}
}
```

aayushtheapple
Автор

Hello Striver, You explain code very well.
Thankyou for such kind of content.

ishwaripednekar
Автор

Thank you striver bhai. I think your way of teaching and delivering the concept is awesome. For me you are not lesser than GOD. I really don't have words to explain my feelings. @striver

gaikwadpratik
Автор

Thank you soo much !!! Recursive and Iterative clearing both the approaches. :))))

shivalikagupta
Автор

Hello Striver, You explain code very well.
Thankyou for such kind of content.

sahilmathur
Автор

We love your series! And I can not thank you enough for your efforts!

sanjana
Автор

Thank you Striver Bhaiya! for your efforts to make such great content !

tanujamaurya
Автор

thanks, bro for making such a wonderful series

abhaytiwari
Автор

dhanetawasi code :-
vector<int> inOrder(Node* root)
{
stack<Node*> st;
vector<int > ans;
if(root!=NULL)
st.push(root);
while(!st.empty())
{
if(root==NULL)
{
st.pop();
if(st.empty())
break;
root =st.top();st.pop();
ans.push_back(root->data);
//right wali ko dalinge
root=root->right;
st.push(root);
continue;
}

st.push(root->left);
root=root->left;
}
return ans;
}

ujjwalsharmaiiitunacse
Автор

striver is not a just a emotion . it is a name !

jambajuice
Автор

vector<int> inorder(Node *root)
{
Node *curr = root;
stack<Node *> s;
vector<int> ans;
while (true)
{
if (curr != NULL){
s.push(curr);
curr = curr->left;
}
else {
if (s.empty()) break;
curr = s.top();
s.pop();
ans.push_back(curr->data);
curr = curr->right;
}
}

return ans;
}

himanshu
Автор

Those who are looking for python solution
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:

inorder=[]
node = root
stack = []

while True:

if node!=None:
stack.append(node)
node=node.left
else:
if len(stack)==0:
break
node=stack.pop()
inorder.append(node.val)
node=node.right

return inorder

fantasyillusion
Автор

Liked. Cfbr will watch after some time

jasonbrody
Автор

great work, and have lots of sponsor ad so that you can provide great videos.

nawabkhan
visit shbcf.ru