39 explicit Node(int64_t _data) {
77 while (
node !=
nullptr) {
89 source.root =
nullptr;
101 while (
node !=
nullptr) {
115 other.root =
nullptr;
127 if (
root ==
nullptr) {
147 for (int64_t value :
values) {
170 if (
root ==
nullptr) {
198 if (
root ==
nullptr) {
199 std::cout <<
"Empty List!\n";
203 std::cout << temp->
data <<
" ";
205 }
while (temp !=
root);
224 std::vector<int64_t> res;
225 if (
root ==
nullptr) {
230 res.push_back(temp->
data);
232 }
while (temp !=
root);
253 std::cout <<
"TEST CASE 1\n";
254 std::cout <<
"Intialized a = {2}\n";
255 std::cout <<
"Expected result: {2}\n";
256 CircularLinkedList a;
257 std::vector<int64_t> res = {2};
259 assert(a.values() == res);
261 std::cout <<
"TEST PASSED!\n\n";
268 std::cout <<
"TEST CASE 2\n";
269 std::cout <<
"Intialized a = {2, 5, 6}\n";
270 std::cout <<
"Expected result: {2, 5, 6}\n";
271 CircularLinkedList a;
272 std::vector<int64_t> res = {2, 5, 6};
276 assert(a.values() == res);
278 std::cout <<
"TEST PASSED!\n\n";
285 std::cout <<
"TEST CASE 3\n";
286 std::cout <<
"Intialized a = {2, 7, 8, 3, 2, 6}\n";
287 std::cout <<
"Expected result: {2, 7, 8, 3, 2, 6}\n";
288 CircularLinkedList a;
289 std::vector<int64_t> res = {2, 7, 8, 3, 2, 6};
290 a.insert({2, 7, 8, 3, 2, 6});
292 assert(a.values() == res);
293 std::cout <<
"TEST PASSED!\n\n";
300 std::cout <<
"TEST CASE 4\n";
301 std::cout <<
"Intialized a = {2, 5}\n";
302 std::cout <<
"Expected result: {5, 2}\n";
303 CircularLinkedList a;
304 std::vector<int64_t> res = {5, 2};
308 assert(a.values(start) == res);
310 std::cout <<
"TEST PASSED!\n\n";
318 std::cout <<
"TEST CASE 5\n";
319 std::cout <<
"Intialized a = {}\n";
320 std::cout <<
"Expected result: Empty List!\n";
321 CircularLinkedList a;
322 std::vector<int64_t> res = {};
323 assert(a.values() == res);
325 std::cout <<
"TEST PASSED!\n\n";
struct node { int data; int height; struct node *left; struct node *right;} node
for std::queue
static void test()
Function to test the correctness of the Circular Linked List.
A class that implements a 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.
CircularLinkedList(const CircularLinkedList ©)
Copy constructor for CircularLinkedList.
void insert(Node *node)
Inserts a given Node into the Circular Linked List.
void insert(int64_t data)
Inserts a single value into the Circular Linked List.
void print(Node *root)
Prints the values of the Circular Linked List, beginning from a given Node to be used as the root.
~CircularLinkedList()
Cleans up memory when destroyed.
std::vector< int64_t > values()
Returns a std::vector of the values of the Circular Linked List.
Node * root
Pointer to the root Node.
CircularLinkedList & operator=(CircularLinkedList &&other) noexcept
Move assignment operator.
CircularLinkedList & operator=(const CircularLinkedList &other)
Copy assignment operator.
CircularLinkedList()
Creates an empty CircularLinkedList.
Node * end
Pointer to the last Node.
CircularLinkedList(CircularLinkedList &&source) noexcept
Move constructor for CircularLinkedList.
void print()
Prints the values of the Circular Linked List, beginning from the root Node.
void insert(const std::vector< int64_t > &values)
Inserts all the values from a vector into the Circular Linked List.
Functions for the Circular Linked List implementation.
Testcases to check Union of Two Arrays.
void test1()
A Test to check an simple case.
void test4()
A Test to check a very large input.
void test3()
A Test to check an invalid shift value.
void test2()
A Test to check an empty vector.
void test5()
A Test to check a shift of zero.
A Node struct that represents a single Node in a Binary Tree.
Node(int64_t _data)
Creates a new Node with some initial data.
Node(int64_t _data, Node *_next)
Creates a new Node with initial data and a successor.
int64_t data
The value of the Node.
Node * next
The Node's successor.