Is my approach correct

I used exactly the same approach as Binary Tree. But I’m not sure whether I’m absolutely correct. Please help. https://ide.codingblocks.com/s/242326

you have not consider some edge case

like

  1. if(s==e)return new node(pre[i++]);
  2. if(index>1)root->left = create(pre, in, s, index-1);

i have modify them now it is working

Modifed Code

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

If my inputs are 5 3 1 7 6 8, it is printing some garbage values. Is it an invalid tree. If the answer is yes, why is it printing garbage values. Please help


Updated link

Also, why are we using the condition if(index > 1) in line . Shouldn’t it be if(index >= 1)

Ya
you are right
It should also >=1
:+1:

And about the input and garbage values please answer

@mohammadabdullahjawwad

input is correct
garbage is due to that error if(index > 1)