Updated source for question three to work with a linked list instead of an array for better memory management