2020-04-30 18:59:05 +00:00
|
|
|
/*#############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
|
|
|
## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ##
|
2020-04-30 19:01:14 +00:00
|
|
|
## About: An example of a circular singly linked list ##
|
2020-04-30 18:59:05 +00:00
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################
|
2020-04-30 19:01:14 +00:00
|
|
|
## circlesinglelist.h
|
2020-04-30 18:59:05 +00:00
|
|
|
*/
|
|
|
|
|
2020-04-30 19:01:14 +00:00
|
|
|
#ifndef CIRCLESINGLELIST_H
|
|
|
|
#define CIRCLESINGLELIST_H
|
2020-04-30 18:59:05 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2020-05-01 04:02:45 +00:00
|
|
|
class CircleSingleList {
|
2020-04-30 18:59:05 +00:00
|
|
|
public:
|
2020-04-30 19:01:14 +00:00
|
|
|
CircleSingleList() : tail(NULL) {};
|
|
|
|
CircleSingleList(const CircleSingleList& rhs);
|
|
|
|
CircleSingleList operator=(CircleSingleList rhs);
|
|
|
|
~CircleSingleList();
|
2020-04-30 18:59:05 +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 04:02:45 +00:00
|
|
|
int peek() const;
|
2020-04-30 18:59:05 +00:00
|
|
|
void print() const;
|
|
|
|
bool find(int val) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Node {
|
|
|
|
int data;
|
|
|
|
Node *next;
|
|
|
|
Node(): data(), next(NULL) {};
|
2020-04-30 19:01:14 +00:00
|
|
|
Node(int val): data(val), next(this) {};
|
2020-04-30 18:59:05 +00:00
|
|
|
};
|
2020-04-30 19:01:14 +00:00
|
|
|
Node *tail;
|
|
|
|
bool insert(int val, Node *&tail);
|
|
|
|
bool insert(int val, int key, Node *&tail);
|
|
|
|
bool remove(int val, Node *&tail);
|
|
|
|
bool replace(int val, int key, Node *&tail);
|
2020-04-30 18:59:05 +00:00
|
|
|
Node* find(int val, Node *start) const;
|
2020-04-30 19:01:14 +00:00
|
|
|
Node* findPrevious(int val) const;
|
2020-04-30 18:59:05 +00:00
|
|
|
void print(Node *start) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|