Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
Program defines the QueueAsLinkedList constructor and Purge methods. In the case of the linked list implementation, it is not necessary to preallocate storage. The constructor simply initializes the list object as an empty list. The running time of the constructor is O(1).
Program: QueueAsLinkedList class constructor and Purge methods.
The Purge method empties the queue by invoking the Purge method provided by the LinkedList class and then sets the count field to zero. Since a linked-list can be purged in constant time, the total running time for the Purge method is O(1).