# Algorithms_in_C++: operations_on_datastructures::circular_linked_list::CircularLinkedList Class Reference

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

## Private Attributes

Node * | root
| Pointer to the root Node.
Node * | end {}
| 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.

{
root = nullptr;
end = nullptr;
}
operations_on_datastructures::circular_linked_list::CircularLinkedList::root
Node * root
Pointer to the root Node.
Definition: circular_linked_list.cpp:59
operations_on_datastructures::circular_linked_list::CircularLinkedList::end
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.

{
erase();
root = nullptr;
Node* node = copy.root;
while (node != nullptr) {
insert(node->data);
node = node->next;
}
}
operations_on_datastructures::circular_linked_list::CircularLinkedList::erase
void erase()
Definition: circular_linked_list.cpp:126
operations_on_datastructures::circular_linked_list::CircularLinkedList::insert
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
std::copy
T copy(T... args)
Node
Definition: linkedlist_implentation_usingarray.cpp:14
node
Definition: avltree.cpp:13
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

  source | rvalue reference to a Circular Linked List

{
root = source.root;
end = source.end;
source.root = nullptr;
source.end = nullptr;
}

## ~CircularLinkedList()

operations_on_datastructures::circular_linked_list::CircularLinkedList::~CircularLinkedList | ( |  | ) |

inline

Cleans up memory when destroyed.

{ 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

{
if (root == nullptr) {
return;
}
Node* node = root;
do {
Node* temp = node;
node = node->next;
delete (temp);
} while (node != root);
root = nullptr;
end = nullptr;
}

## 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

  values | The vector of integer values that is to be inserted

Returns
  void

{
for (int64_t value : values) {
insert(value);
}
}
operations_on_datastructures::circular_linked_list::CircularLinkedList::values
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

  data | The integer valus to be inserted

Returns
  void

{
Node* node = new Node(data, root);
insert(node);
}
data
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

  node | The 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

{
if (root == nullptr) {
root = node; ///< Set node as the root
node->next = root; ///< Point node to itself
end = root; ///< Set the end to the root
} else {
end->next = node; ///< Append node to the end
node->next = root; ///< Set the next value to the root
end = node; ///< Make end point to node
}
}
operations_on_datastructures::circular_linked_list::Node::next
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

  other | rvalue reference to a Circular Linked List

Returns
  Reference to CircularLinkedList

{
root = other.root;
end = other.end;
other.root = nullptr;
other.end = nullptr;
return *this;
}

## operator=() [2/2]

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

inline

Copy assignment operator.

Parameters

  other | Reference to a Circular Linked List

Returns
  Reference to CircularLinkedList

{
erase();
root = nullptr;
Node* node = other.root;
while (node != nullptr) {
insert(node->data);
node = node->next;
}
return *this;
}
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

{ print(root); }
operations_on_datastructures::circular_linked_list::CircularLinkedList::print
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

  root | The Node to start at

Returns
  void

{
Node* temp = root;
if (root == nullptr) {
std::cout << "Empty List!\n";
return;
}
do {
std::cout << temp->data << " ";
temp = temp->next;
} while (temp != root);
std::cout << "\n";
}
std::cout

## 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

{ 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

  root | The Node to start at

Returns
  A std::vector of the list's values

< Return empty vector

{
std::vector<int64_t> res;
if (root == nullptr) {
return res; ///< Return empty vector
}
Node* temp = root;
do {
res.push_back(temp->data);
temp = temp->next;
} while (temp != root);
return res;
}
std::vector::push_back
T push_back(T... args)
std::vector
Here is the call graph for this function:

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

- operations_on_datastructures/circular_linked_list.cpp