Creating a linked list |
A linked list can be developed produced in a array. Consider the array below -
Data | Pointer | |
0 | Bob | 1 |
1 | Fred | 2 |
2 | Sue | x |
3 | 4 | |
4 | 5 | |
5 | 6 | |
6 | 7 | |
7 | 8 | |
8 | 9 | |
9 | x |
- StartOfList = 0
- FreeSpace = 3
The pointer will show the next value in the list. The StartOfList pointer will point to the start of the list while FreeSpace points to the next "free" block. A "x" pointer represents the end of the list. This will be the situation when a list starts off. But over time as values are added and removed you could get a table which looks like this.
0 | 2 | |
1 | Fred | 5 |
2 | 4 | |
3 | 6 | |
4 | 3 | |
5 | Bert | 8 |
6 | 9 | |
7 | x | |
8 | Charlotte | x |
9 | 7 |
- StartOfList = 1
- FreeSpace = 0
The linked list of data is -
1 -> 5 -> 8
The free space list is -
0 -> 2 -> 4 -> 3 -> 6 -> 9 -> 7