Difference between revisions of "Linked Lists - Lists"
(Added adding and hiding in a lis) |
|||
Line 1: | Line 1: | ||
− | A linked list is a list where each value is aware of the data that comes before and after the value. 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. | + | =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 | ||
+ | |||
+ | =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 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. | 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. |
Revision as of 10:29, 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
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.