2020-07-23 21:58:18 +00:00
|
|
|
/*#############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
|
|
|
## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ##
|
|
|
|
## About: An example of a queue implementation using linked lists ##
|
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################
|
|
|
|
## queuelist.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QUEUELIST_H
|
|
|
|
#define QUEUELIST_H
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2020-07-30 22:44:01 +00:00
|
|
|
|
|
|
|
#define TYPE std::string
|
|
|
|
|
|
|
|
template <typename T>
|
2020-07-23 21:58:18 +00:00
|
|
|
class QueueList {
|
|
|
|
public:
|
|
|
|
QueueList() : head(NULL), tail(NULL){};
|
2020-07-30 22:44:01 +00:00
|
|
|
QueueList(const QueueList<T>& rhs);
|
|
|
|
QueueList operator=(QueueList<T> rhs);
|
2020-07-23 21:58:18 +00:00
|
|
|
~QueueList();
|
2020-07-30 22:44:01 +00:00
|
|
|
bool enqueue(T val);
|
|
|
|
T dequeue();
|
|
|
|
T next() const;
|
2020-07-23 21:58:18 +00:00
|
|
|
bool isEmpty() const;
|
|
|
|
void print() const;
|
|
|
|
void makeEmpty();
|
|
|
|
|
|
|
|
private:
|
2020-07-30 22:44:01 +00:00
|
|
|
template<typename TY>
|
2020-07-23 21:58:18 +00:00
|
|
|
struct Node {
|
2020-07-30 22:44:01 +00:00
|
|
|
TY data;
|
2020-07-23 21:58:18 +00:00
|
|
|
Node *next;
|
|
|
|
Node(): data(), next(NULL) {};
|
2020-07-30 22:44:01 +00:00
|
|
|
Node(TY val): data(val), next(NULL) {};
|
2020-07-23 21:58:18 +00:00
|
|
|
};
|
2020-07-30 22:44:01 +00:00
|
|
|
Node<T> *head, *tail;
|
|
|
|
bool enqueue(T val, Node<T> *&head);
|
|
|
|
T dequeue(Node<T> *&tail);
|
|
|
|
void print(Node<T> *start) const;
|
|
|
|
void makeEmpty(Node<T> *&head);
|
2020-07-23 21:58:18 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|