ABSTRACT

The function List insert in Section 18.3 always inserts the new value at the beginning of the list. If we always delete nodes from the front of the list, then the linked list is a stack. In this problem we change the insert function so that the first inserted value is at the beginning of the list and the latest inserted value is at the end of the list. If we still remove elements from the beginning of the list we have created a queue, like a line at a store waiting for service. The implementation below uses recursion.