Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A Queue class based on a DLL implementation.
- // Work in this implementation is delegated to a DLList object.
- // A queue can be implemented as a linked list by adding to one end and deleting from
- // the other end. For example, AddToTail + DeleteHead or AddToHead + DeleteTail.
- // DeleteTail should be avoided with singly linked lists.
- #include "Header.h"
- template <class T>
- class QueueDLL
- {
- public:
- QueueDLL();
- ~QueueDLL();
- void Enqueue(T& val); // Adds an element to the queue.
- T Dequeue(void); // Returns and removes from the queue the first
- // element added to the queue.
- T GetFirst(void); // Returns the first element added to the queue.
- T GetLast(void); // Returns the last element added to the queue.
- bool IsEmpty(void);
- void Clear(void);
- private:
- DLList<T> list;
- };
- // Constructor.
- // Automatically calls the constructor of the DLList.
- template <class T>
- QueueDLL<T>::QueueDLL(void)
- {}
- // Destructor.
- // Automatically calls the destructor of the DLList.
- template <class T>
- QueueDLL<T>::~QueueDLL(void)
- {}
- template <class T>
- void QueueDLL<T>::Enqueue(T& el)
- {
- list.AddToTail(el);
- }
- template <class T>
- T QueueDLL<T>::Dequeue()
- {
- T el = list.GetHead();
- list.DeleteFromHead();
- return el;
- }
- template <class T>
- T QueueDLL<T>::GetFirst()
- {
- return list.GetHead();
- }
- template <class T>
- T QueueDLL<T>::GetLast()
- {
- return list.GetTail();
- }
- template <class T>
- bool QueueDLL<T>::IsEmpty(void)
- {
- return list.IsEmpty();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement