I was trying to perform Inorder traversal of BST without recursion.
At a particular line of code I was getting error, Code:
Initially I defined out as:
out=[]
elif stack!=[]:
current=stack.pop()
out+=(current.val)
current=current.right
Error:
Traceback (most recent call last):
File "main.py", line 224, in
Z = obj.inorderTraversal(A)
File "/tmp/judge/solution.py", line 16, in inorderTraversal
out+=(current.val)
TypeError: 'int' object is not iterable
Then I changed out+=(current.val) to out.append(current.val), It worked.
Can anyone help me understand this??
Basically, Whats the diff b/w both statements??