I was writing this code to create a binary tree from inorder and postorder traversals and I stumbled on a recursive solution that was confusing, because the program behaved like a tail-recursive call instead of standard recursion.
I've transformed the code into something general so that it's easier for everyone to understand
class Test:
def func(self, array):
if not array:
return 0
print(array)
array.pop(0)
temp1 = self.func(array)
temp2 = self.func(array)
x = [1,2,3,4,5,6]
temp = Test()
temp.func(x)
I expect the 2 function calls to have the same output twice. That is the first call should result in [2,3,4,5,6], [3,4,5,6] ... [6]. The second function call should do the same. Instead, the second call results in nothing happening. Shouldn't the recursion stack hold the current state of the array, why is it getting updated?