Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
operations_on_datastructures::circular_linked_list::CircularLinkedList Class Reference

A class that implements a Circular Linked List. More...

Collaboration diagram for operations_on_datastructures::circular_linked_list::CircularLinkedList:
[legend]

Public Member Functions

 CircularLinkedList ()
 Creates an empty CircularLinkedList.
 
 CircularLinkedList (const CircularLinkedList &copy)
 Copy constructor for CircularLinkedList.
 
 CircularLinkedList (CircularLinkedList &&source) noexcept
 Move constructor for CircularLinkedList.
 
CircularLinkedListoperator= (const CircularLinkedList &other)
 Copy assignment operator.
 
CircularLinkedListoperator= (CircularLinkedList &&other) noexcept
 Move assignment operator.
 
 ~CircularLinkedList ()
 Cleans up memory when destroyed.
 
void erase ()
 
void insert (const std::vector< int64_t > &values)
 Inserts all the values from a vector into the Circular Linked List.
 
void insert (int64_t data)
 Inserts a single value into the Circular Linked List.
 
void insert (Node *node)
 Inserts a given Node into the Circular Linked List.
 
void print ()
 Prints the values of the Circular Linked List, beginning from the root Node.
 
void print (Node *root)
 Prints the values of the Circular Linked List, beginning from a given Node to be used as the root.
 
std::vector< int64_t > values ()
 Returns a std::vector of the values of the Circular Linked List.
 
std::vector< int64_t > values (Node *root)
 Returns a std::vector of the values of the Circular Linked List, beginning from a given Node.
 

Private Attributes

Noderoot
 Pointer to the root Node.
 
Nodeend {}
 Pointer to the last Node.
 

Detailed Description

A class that implements a Circular Linked List.

Constructor & Destructor Documentation

◆ CircularLinkedList() [1/3]

operations_on_datastructures::circular_linked_list::CircularLinkedList::CircularLinkedList ( )
inline

Creates an empty CircularLinkedList.

66 {
67 root = nullptr;
68 end = nullptr;
69 }
Node * root
Pointer to the root Node.
Definition circular_linked_list.cpp:59
Node * end
Pointer to the last Node.
Definition circular_linked_list.cpp:60

◆ CircularLinkedList() [2/3]

operations_on_datastructures::circular_linked_list::CircularLinkedList::CircularLinkedList ( const CircularLinkedList & copy)
inline

Copy constructor for CircularLinkedList.

73 {
74 erase();
75 root = nullptr;
76 Node* node = copy.root;
77 while (node != nullptr) {
78 insert(node->data);
79 node = node->next;
80 }
81 }
void insert(const std::vector< int64_t > &values)
Inserts all the values from a vector into the Circular Linked List.
Definition circular_linked_list.cpp:146
T copy(T... args)
Definition linkedlist_implentation_usingarray.cpp:14
Definition binary_search_tree.cpp:11
Here is the call graph for this function:

◆ CircularLinkedList() [3/3]

operations_on_datastructures::circular_linked_list::CircularLinkedList::CircularLinkedList ( CircularLinkedList && source)
inlinenoexcept

Move constructor for CircularLinkedList.

Parameters
sourcervalue reference to a Circular Linked List
86 {
87 root = source.root;
88 end = source.end;
89 source.root = nullptr;
90 source.end = nullptr;
91 }

◆ ~CircularLinkedList()

operations_on_datastructures::circular_linked_list::CircularLinkedList::~CircularLinkedList ( )
inline

Cleans up memory when destroyed.

122{ erase(); }
Here is the call graph for this function:

Member Function Documentation

◆ erase()

void operations_on_datastructures::circular_linked_list::CircularLinkedList::erase ( )
inline

Iteratively frees each node in the Circular Linked List from the heap

126 {
127 if (root == nullptr) {
128 return;
129 }
130 Node* node = root;
131 do {
132 Node* temp = node;
133 node = node->next;
134 delete (temp);
135 } while (node != root);
136 root = nullptr;
137 end = nullptr;
138 }
struct node { int data; int height; struct node *left; struct node *right;} node
for std::queue
Definition avltree.cpp:13

◆ insert() [1/3]

void operations_on_datastructures::circular_linked_list::CircularLinkedList::insert ( const std::vector< int64_t > & values)
inline

Inserts all the values from a vector into the Circular Linked List.

Goes through each element in the vector sequentially, inserting it into the list

Parameters
valuesThe vector of integer values that is to be inserted
Returns
void
146 {
147 for (int64_t value : values) {
148 insert(value);
149 }
150 }
std::vector< int64_t > values()
Returns a std::vector of the values of the Circular Linked List.
Definition circular_linked_list.cpp:214
Here is the call graph for this function:

◆ insert() [2/3]

void operations_on_datastructures::circular_linked_list::CircularLinkedList::insert ( int64_t data)
inline

Inserts a single value into the Circular Linked List.

Creates a Node with the given value, pointing to the root Node and inserts it into the list

Parameters
dataThe integer valus to be inserted
Returns
void
158 {
159 Node* node = new Node(data, root);
160 insert(node);
161 }
int data[MAX]
test data
Definition hash_search.cpp:24
Here is the call graph for this function:

◆ insert() [3/3]

void operations_on_datastructures::circular_linked_list::CircularLinkedList::insert ( Node * node)
inline

Inserts a given Node into the Circular Linked List.

Checks wheter the list is empty, and inserts the Node, modifying the end pointer

Parameters
nodeThe Node that is to be inserted
Returns
void

< Set node as the root

< Point node to itself

< Set the end to the root

< Append node to the end

< Set the next value to the root

< Make end point to node

169 {
170 if (root == nullptr) {
171 root = node; ///< Set node as the root
172 node->next = root; ///< Point node to itself
173 end = root; ///< Set the end to the root
174 } else {
175 end->next = node; ///< Append node to the end
176 node->next = root; ///< Set the next value to the root
177 end = node; ///< Make end point to node
178 }
179 }
Node * next
The Node's successor.
Definition circular_linked_list.cpp:34

◆ operator=() [1/2]

CircularLinkedList & operations_on_datastructures::circular_linked_list::CircularLinkedList::operator= ( CircularLinkedList && other)
inlinenoexcept

Move assignment operator.

Parameters
otherrvalue reference to a Circular Linked List
Returns
Reference to CircularLinkedList
112 {
113 root = other.root;
114 end = other.end;
115 other.root = nullptr;
116 other.end = nullptr;
117 return *this;
118 }

◆ operator=() [2/2]

CircularLinkedList & operations_on_datastructures::circular_linked_list::CircularLinkedList::operator= ( const CircularLinkedList & other)
inline

Copy assignment operator.

Parameters
otherReference to a Circular Linked List
Returns
Reference to CircularLinkedList
97 {
98 erase();
99 root = nullptr;
100 Node* node = other.root;
101 while (node != nullptr) {
102 insert(node->data);
103 node = node->next;
104 }
105 return *this;
106 }
Here is the call graph for this function:

◆ print() [1/2]

void operations_on_datastructures::circular_linked_list::CircularLinkedList::print ( )
inline

Prints the values of the Circular Linked List, beginning from the root Node.

Goes through each Node from the root and prints them out in order

Returns
void
187{ print(root); }
void print()
Prints the values of the Circular Linked List, beginning from the root Node.
Definition circular_linked_list.cpp:187
Here is the call graph for this function:

◆ print() [2/2]

void operations_on_datastructures::circular_linked_list::CircularLinkedList::print ( Node * root)
inline

Prints the values of the Circular Linked List, beginning from a given Node to be used as the root.

Goes through each Node from the given Node and prints them out in order. If the list is empty, it prints the message 'Empty List!'

Parameters
rootThe Node to start at
Returns
void
196 {
197 Node* temp = root;
198 if (root == nullptr) {
199 std::cout << "Empty List!\n";
200 return;
201 }
202 do {
203 std::cout << temp->data << " ";
204 temp = temp->next;
205 } while (temp != root);
206 std::cout << "\n";
207 }

◆ values() [1/2]

std::vector< int64_t > operations_on_datastructures::circular_linked_list::CircularLinkedList::values ( )
inline

Returns a std::vector of the values of the Circular Linked List.

Starting from the root Node, appends each value of the list to a std::vector and returns it

Returns
A std::vector of the list's values
214{ return values(root); }
Here is the call graph for this function:

◆ values() [2/2]

std::vector< int64_t > operations_on_datastructures::circular_linked_list::CircularLinkedList::values ( Node * root)
inline

Returns a std::vector of the values of the Circular Linked List, beginning from a given Node.

Starting from a given Node, appends each value of the list to a std::vector and returns it

Parameters
rootThe Node to start at
Returns
A std::vector of the list's values

< Return empty vector

223 {
225 if (root == nullptr) {
226 return res; ///< Return empty vector
227 }
228 Node* temp = root;
229 do {
230 res.push_back(temp->data);
231 temp = temp->next;
232 } while (temp != root);
233 return res;
234 }
T push_back(T... args)
Here is the call graph for this function:

Member Data Documentation

◆ end

Node* operations_on_datastructures::circular_linked_list::CircularLinkedList::end {}
private

Pointer to the last Node.

60{}; ///< Pointer to the last Node

The documentation for this class was generated from the following file: