##### [Double-linked lists] There's problems in my insert() method, I cant figure out why.

When insert() at tail(), the contents of the list is incorrect. In other words, the order of the list is in correct.

You can run the code to see where the problem is. main.cpp has all the test to determine my double-linked lists is efficient.

*My codes are in dlist.hpp / main.cpp is the tester*

**Voters**

Highwayman (1483)

um. I know this is kind of unrelated, but

```
node(int value, node* next, node* prev) :
value(value), next(next), prev(prev)
{ }
```

seems kinda dangerous...

the conditional code beginning on line 62 inserts the node

afterthe tail instead of before.@Highwayman can you elaborate more on it? I don't think I get it yet.

Sure. I accidentally pointed out the wrong thing anyways kind of.

Basically, in the last two cases of your insert method, the actual effects are changed slightly. This makes it clear that one of these ways is doing your insert incorrectly. In order to fix this, you have to change the behavior of one of these conditional blocks to match the other.

let's look at your code.

Ok, so looking at the comment, we see that the correct behavior of this function is to link in a new node after the passed node (previous).

But we have one of your cases

notlinking the node in after, butbeforethe given node, specifically the`else`

code block:This is your incorrect behavior. I hope that's more helpful :)

@TuanTran17

@Highwayman I see what you mean, ill work on it.