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 doubly linked list ##
|
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################
|
|
|
|
## doublelist.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DOUBLELIST_H
|
|
|
|
#define DOUBLELIST_H
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2020-07-30 23:16:29 +00:00
|
|
|
|
|
|
|
#define TYPE std::string
|
|
|
|
|
2020-07-30 20:39:28 +00:00
|
|
|
template <typename T>
|
2020-07-23 21:58:18 +00:00
|
|
|
class DoubleList {
|
|
|
|
public:
|
|
|
|
DoubleList() : head(NULL) {};
|
|
|
|
DoubleList(const DoubleList& rhs);
|
|
|
|
DoubleList operator=(DoubleList rhs);
|
|
|
|
~DoubleList();
|
2020-07-30 20:39:28 +00:00
|
|
|
bool insert(T val);
|
|
|
|
bool insert(T val, T key);
|
|
|
|
bool remove(T val);
|
|
|
|
bool replace(T val, T key);
|
2020-07-23 21:58:18 +00:00
|
|
|
void makeEmpty();
|
|
|
|
bool isEmpty() const;
|
2020-07-30 20:39:28 +00:00
|
|
|
T peek() const;
|
2020-07-23 21:58:18 +00:00
|
|
|
void print() const;
|
2020-07-30 20:39:28 +00:00
|
|
|
bool find(T val) const;
|
2020-07-23 21:58:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct Node {
|
2020-07-30 23:16:29 +00:00
|
|
|
TYPE data;
|
2020-07-23 21:58:18 +00:00
|
|
|
Node *next, *prev;
|
|
|
|
Node(): data(), next(NULL), prev(NULL) {};
|
2020-07-30 23:16:29 +00:00
|
|
|
Node(TYPE val): data(val), next(NULL), prev(NULL) {};
|
2020-07-23 21:58:18 +00:00
|
|
|
};
|
2020-07-30 23:16:29 +00:00
|
|
|
Node *head;
|
|
|
|
bool insert(T val, Node *&head);
|
|
|
|
bool insert(T val, T key, Node *&head);
|
|
|
|
bool remove(T val, Node *&head);
|
|
|
|
bool replace(T val, T key, Node *&head);
|
|
|
|
Node* find(T val, Node *start) const;
|
|
|
|
void print(Node *start) const;
|
2020-07-23 21:58:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|