DoubleLinkList Append Value

  c++, doubly-linked-list

I have a question: How the first Node in my double link list get the value? Could someone explain it? Because what i see in append_value function is to add the end Node value not the first Node value. But when i try to run the code, the first Node somehow has some value. thanks.

Please see the code:

struct Node
 {
 int value;
 Node *next;
 Node *prev;
 };

class DoubleLinkList
{
    private:
        Node *first;
        Node *end;
    public:
        DoubleLinkList();
        void show_list();
        void append_value(int);
};

DoubleLinkList::DoubleLinkList()
{
 first = NULL;
 end = NULL;
} 

void DoubleLinkList::show_list()
{
 Node *node;
 node = first;
    while(node)
    {
    cout << node->value << " ";
    node = node->next;
    }
    cout << endl;
}

void DoubleLinkList::append_value(int value)
{
 Node *ptr = end;
 end = new Node;
if (first == NULL)
 first = end;
else
 ptr->next = end;
if(end)
 {
   end->next = NULL;
   end->prev = ptr;
   end->value = value;
 }
}

Source: Windows Questions C++

LEAVE A COMMENT