Difference between revisions of "Linked Lists - Lists"
(→Linked List) |
|||
Line 9: | Line 9: | ||
*set this pointer value so it points to the new item | *set this pointer value so it points to the new item | ||
*set the pointer of the new value to the copied pointer value | *set the pointer of the new value to the copied pointer value | ||
+ | |||
+ | To delete an item from the linked list: | ||
+ | *Find the item you wish to delete | ||
+ | *Copy the pointer value of this item | ||
+ | *Find the item which points to the item to delete | ||
+ | *Replace the pointer value of this item to the copied value | ||
=Expanded Version= | =Expanded Version= |
Revision as of 10:32, 4 October 2018
Linked List
A linked list is a list where each value is aware of the data that comes before and after the value.
This is achieved by each node having a data value to store the data and a pointer value to point to the next item in the list.
To add an item into the linked list:
- you can put the new data into a current space
- find the value it needs to go after and copy the pointer value
- set this pointer value so it points to the new item
- set the pointer of the new value to the copied pointer value
To delete an item from the linked list:
- Find the item you wish to delete
- Copy the pointer value of this item
- Find the item which points to the item to delete
- Replace the pointer value of this item to the copied value
Expanded Version
They have two lists, one contains the spaces within the list where a value can be placed the other contains the values with a pointer to the next.
To add to a linked list the new value must be placed in a space and assigned the pointer that the old value (or empty) was holding.
To stop a list finding a value while keeping it in the list, the pointer from the removed value can be moved to the value that used to point to the removed value.