Double linked list

Can anyone tell me whats going wrong in my code?
Its running locally but won’t run in ide.
Also expected out is not matching for first node.

Hello @sounakume,

Please, share your code with me.
Share it using online coding block IDE.

Sorry i forgot to include that, check for doubleLL function

Hello @sounakume,

It is working correctly:
https://ide.geeksforgeeks.org/Fg5nb79gab

What is the problem?

But the output is
1<–>2<–>3<–>5<–>6<–>7<–>8<–>

should not it be
2<–>1<–>3<–>5<–>6<–>7<–>8<–> ??

Nope @sounakume, it shouldn’t be what you have specified.

Reason:
It is a BST.
So, 2 is the right child of 1.
And as per your code,

  1. you will first go to the leftmost node i.e. 1 in this code
  2. Print it’s value.
  3. then go for the right child.

Hope, this would help.
Give a like if you are satisfied.

1 Like

yes yes i got it, the way im printing the tree got me confused.

Hey @sounakume,

Yup, it happens sometimes. No worries.
Don’t forget to mark this as resolved.