- 1

Linked List C++

For the implementation of linked list in C++, I saw each pointer point to a node. Is there anyway to rewrite those functions so that I only need to use 1 pointer to insert new nodes? (I tried once but the delete just destroy the node)

16th Apr 2019, 11:37 PM
Mike
Mike - avatar
1 Respuesta
- 1
A linked list is a datastructure that consists of pieces of memory with the list element and a pointer to the next element in memory. This is a singly linked list. A double linked list also has a pointer pointing to the previous element. To insert a node you have to make the last pointer point to the new node. For delete it is important to first delete the last node and then set the pointer of the previous node to NULL. If you first set the previous pointer to NULL, you have will have a memory leak. I dont know if this answers your question but pointers are a major part of linked lists, every node should have 1 or 2.
20th Apr 2019, 7:05 AM
Bram