klips/cpp/datastructs/doublelist/doublelist.h

49 lines
1.5 KiB
C
Raw Permalink Normal View History

2020-05-01 03:40:35 +00:00
/*#############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ##
2020-05-01 03:43:25 +00:00
## About: An example of a doubly linked list ##
2020-05-01 03:40:35 +00:00
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
2020-05-01 03:43:25 +00:00
## doublelist.h
2020-05-01 03:40:35 +00:00
*/
2020-05-01 03:43:25 +00:00
#ifndef DOUBLELIST_H
#define DOUBLELIST_H
2020-05-01 03:40:35 +00:00
#include <iostream>
2020-05-01 03:43:25 +00:00
class DoubleList {
2020-05-01 03:40:35 +00:00
public:
2020-05-01 03:43:25 +00:00
DoubleList() : head(NULL) {};
DoubleList(const DoubleList& rhs);
DoubleList operator=(DoubleList rhs);
~DoubleList();
2020-05-01 03:40:35 +00:00
bool insert(int val);
bool insert(int val, int key);
bool remove(int val);
bool replace(int val, int key);
void makeEmpty();
bool isEmpty() const;
2020-05-01 03:43:25 +00:00
int peek() const;
2020-05-01 03:40:35 +00:00
void print() const;
bool find(int val) const;
private:
struct Node {
int data;
2020-05-01 03:43:25 +00:00
Node *next, *prev;
Node(): data(), next(NULL), prev(NULL) {};
Node(int val): data(val), next(NULL), prev(NULL) {};
2020-05-01 03:40:35 +00:00
};
Node *head;
bool insert(int val, Node *&head);
bool insert(int val, int key, Node *&head);
bool remove(int val, Node *&head);
bool replace(int val, int key, Node *&head);
Node* find(int val, Node *start) const;
void print(Node *start) const;
};
#endif