0 Charlotte 1
1 Fred 2
2 Bert x
3   4
4   5
5   6
6   7
7   8
8   9
9   x

A queue is First in first out. This means that we can not add or remove nodes in the middle of the queue. The algorithims for adding / removing are

Adding

  1. Look at the node pointed to by the "HeadOfQueue" pointer
  2. Follow the pointers until you reach the end of the queue.
  3. Make this pointer point to "freeSpace" (the start of the free space queue)
  4. Add the data to the node pointed to by "freeSpace"
  5. Set the "FreeSpace" pointer to be the next free node (follow the pointer from the new node)
  6. Set the new nodes pointer to be x (or null)

Removing

  1. If the HeadOfQueue points to null then return a erorr (i.e. the queue is empty)
  2. Start at the HeadOfQueue
  3. Set the nodes pointer to be the same as "FreeSpace"
  4. HeadOfQueue will be copied over to the FreeSpace