2020-04-15 15:58:07 +00:00
|
|
|
/*#############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
|
|
|
## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ##
|
|
|
|
## About: An example of a singly linked list ##
|
|
|
|
## ##
|
|
|
|
## Structure: Remove: Insert: Insert at: Replace: ##
|
|
|
|
## o-o-o-o-o-o o-o--x-->o-o-o o o o ##
|
|
|
|
## | /| / \ ##
|
2020-04-20 02:37:05 +00:00
|
|
|
## o-o-o-o-o-o o-o~o-o-o-o o-o~x~o-o-o ##
|
2020-04-15 15:58:07 +00:00
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################
|
2020-04-20 02:37:05 +00:00
|
|
|
## singlelist.h
|
2020-04-15 15:58:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LINKEDLIST_H
|
|
|
|
#define LINKEDLIST_H
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
class SingleList{
|
|
|
|
public:
|
|
|
|
SingleList() : head(NULL) {};
|
|
|
|
SingleList(const SingleList& rhs);
|
2020-04-27 01:47:59 +00:00
|
|
|
SingleList operator=(SingleList rhs);
|
2020-04-15 15:58:07 +00:00
|
|
|
~SingleList();
|
|
|
|
bool insert(int val);
|
|
|
|
bool insert(int val, int key);
|
2020-04-15 16:08:04 +00:00
|
|
|
bool remove(int val);
|
|
|
|
bool replace(int val, int key);
|
2020-04-15 15:58:07 +00:00
|
|
|
void makeEmpty();
|
|
|
|
bool isEmpty() const;
|
2020-04-15 16:08:04 +00:00
|
|
|
void peek() const;
|
2020-04-15 15:58:07 +00:00
|
|
|
void print() const;
|
|
|
|
bool find(int val) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Node {
|
|
|
|
int data;
|
|
|
|
Node *next;
|
2020-04-20 02:37:05 +00:00
|
|
|
Node(): data(), next(NULL) {};
|
2020-04-15 15:58:07 +00:00
|
|
|
Node(int val): data(val), next(NULL) {};
|
|
|
|
};
|
|
|
|
Node *head;
|
2020-04-15 16:08:04 +00:00
|
|
|
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);
|
2020-04-15 15:58:07 +00:00
|
|
|
Node* find(int val, Node *start) const;
|
|
|
|
Node* findPrevious(int val, Node *start) const;
|
|
|
|
void print(Node *start) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|