double linked list

1
2
3
4
5
6
7
8
9
10
11
12
struct list
{
    struct node
    {
        int data;
        node *next;
        node *last;
    };
    node *head;
    node *tail ;
};


how can I make a double linked list Using the code above?

Someone explain it to me plz

sorry for my bad english
Last edited on
The best way's to think about it is that head and tail will point to the first and last node, respectively, in your list. The default constructor should make them NULL. When adding a node, you have to adjust the head and tail pointers to point to the correct node (if adding to the front, have head point to it, if adding to the rear, have tail point to it). Each node pointer of a node (next and last) should point to the correct nodes. The current node's next should point at the node next in line while the current node's last should point to the previous node.
I do not know how to implement a double-linked list with using this structure node. I think it is impossible to do. To implement a double-linked list the structure node should look the following way

1
2
3
4
5
6
    struct node
    {
        int data;
        node *next;
        node *prev;
    };
Last edited on
@vlad from moscow
Semantics! The OP can use any variable name he wants. Even a and b if so desired.

I still don't believe that's going to help him design the linked list by just changing the node pointer name.
Wrong names mean wrong code. Wrong words in a sentence give another meaning of the sentence.
So it is very important to use right names that others could understand what you mean.
I have a better opinion about the author of the thread than you have and I think he is clever enough to understand the difference in his notation and main.

Last edited on
Topic archived. No new replies allowed.