2. Linked Lists
A linked list is a set of items which are arranged in an
sequential order, like an array, but each item links to the next
item in the list.
Linked lists have advantages and disadvantages:
3. Advantages of Linked Lists
No fixed size: the list can expand or reduce when the program
is run.
Linked lists are flexible: the order within the lists can be
changed without having to move data (just the links are
moved).
Memory efficient than an array: only needs to be the size
required for the number of items stored, not as large as the
possible number of items to be stored.
4. Disadvantages of Linked Lists
Cannot use an index within a linked list to identify a particular
item. To find a specific item you need to go through the list
from beginning to end.
5. Inserting and Adding Items
Inserting an item between two present items within a list can be achieved
by changing the link of the pointer to point to the inserted item.
Adding an item to the end of the list can be done by redirecting the last
link to the new item and linking the new item to NUL .
Adding an item to the beginning of the list can be done by redirecting the
Head of the list to the new item and pointing its link to the formal first
item.
6. Deleting Items
Deleting an item from a list would be achieved by changing the link from
the item before to the item after, bypassing the item which is no longer
required.