chore: use iwyu on data_structures/**.cpp

This commit is contained in:
realstealthninja
2024-09-13 15:37:49 +05:30
parent 24e597f7e2
commit a3b719e368
30 changed files with 602 additions and 634 deletions

View File

@@ -6,7 +6,8 @@
* \warning This program is a poor implementation - C style - and does not
* utilize any of the C++ STL features.
*/
#include <iostream>
#include <cstddef> // for NULL
#include <iostream> // for operator<<, basic_ostream, char_traits, cout
struct node {
int val;
@@ -145,28 +146,28 @@ int main() {
std::cin >> ch;
int x;
switch (ch) {
case 1:
std::cout << "\nEnter the value to be Inserted : ";
std::cin >> x;
Insert(root, x);
break;
case 2:
std::cout << "\nEnter the value to be Deleted : ";
std::cin >> x;
Remove(root, root, x);
break;
case 3:
BFT(root);
break;
case 4:
Pre(root);
break;
case 5:
In(root);
break;
case 6:
Post(root);
break;
case 1:
std::cout << "\nEnter the value to be Inserted : ";
std::cin >> x;
Insert(root, x);
break;
case 2:
std::cout << "\nEnter the value to be Deleted : ";
std::cin >> x;
Remove(root, root, x);
break;
case 3:
BFT(root);
break;
case 4:
Pre(root);
break;
case 5:
In(root);
break;
case 6:
Post(root);
break;
}
} while (ch != 0);

View File

@@ -5,11 +5,13 @@
* @see binary_search_tree.cpp
*/
#include <cassert>
#include <functional>
#include <iostream>
#include <memory>
#include <vector>
#include <cassert> // for assert
#include <functional> // for function
#include <iostream> // for basic_ostream, operator<<, cout, char_traits
#include <memory> // for operator==, unique_ptr, allocator
#include <vector> // for vector, operator==
#include <cstddef> // for size_t
#include <utility> // for move
/**
* @brief The Binary Search Tree class.

View File

@@ -22,12 +22,13 @@
* @author [DanArmor](https://github.com/DanArmor)
*/
#include <cassert> /// for assert
#include <functional> /// for list of hash functions for bloom filter constructor
#include <initializer_list> /// for initializer_list for bloom filter constructor
#include <string> /// for testing on strings
#include <vector> /// for std::vector
#include <iostream> /// for IO operations
#include <cassert> // for assert
#include <functional> // for function
#include <initializer_list> // for initializer_list
#include <string> // for basic_string, string
#include <vector> // for vector
#include <iostream> // for operator<<, basic_ostream, cout
#include <cstddef> // for size_t
/**
* @namespace data_structures

View File

@@ -2,6 +2,10 @@
A simple class for Cicular Linear Linked List
*/
#include "cll.h"
#include <cstdlib> // for NULL
#include <iostream> // for basic_ostream, char_traits, operator<<, cout
using namespace std;
/* Constructor */

View File

@@ -1,4 +1,7 @@
#include "cll.h"
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
#include "cll.h" // for cll
using namespace std;
int main() {

View File

@@ -1,6 +1,5 @@
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstdio> // for NULL
#include <iostream> // for operator<<, basic_ostream, cout, char_traits
struct node {
int val;

View File

@@ -18,10 +18,12 @@
* @see dsu_union_rank.cpp
*/
#include <cassert> /// for assert
#include <cstdint> /// for integral typedefs
#include <iostream> /// for IO operations
#include <vector> /// for std::vector
#include <cassert> // for assert
#include <cstdint> // for uint64_t
#include <iostream> // for char_traits, basic_ostream, operator<<, cout, endl
#include <vector> // for vector
#include <algorithm> // for max, min
#include <utility> // for swap
using std::cout;
using std::endl;

View File

@@ -19,10 +19,11 @@
* @see dsu_path_compression.cpp
*/
#include <cassert> /// for assert
#include <cstdint> /// for integral typedefs
#include <iostream> /// for IO operations
#include <vector> /// for std::vector
#include <cassert> // for assert
#include <cstdint> // for uint64_t
#include <iostream> // for char_traits, basic_ostream, operator<<, cout, endl
#include <vector> // for vector
#include <utility> // for swap
using std::cout;
using std::endl;

View File

@@ -14,9 +14,10 @@
* to point to the node that the current node is pointing to, and then returning
* the current node to heap store.
*/
#include <iostream>
#include <memory>
#include <string>
#include <ctype.h> // for isdigit
#include <iostream> // for operator<<, basic_ostream, cout, basic_istream, cin
#include <memory> // for shared_ptr, __shared_ptr_access, make_shared
#include <string> // for char_traits, basic_string, operator>>, stoi, string
/**
* @namespace data_structures

View File

@@ -14,10 +14,11 @@
* and print the list.
*/
#include <array> /// for std::array
#include <cassert> /// for assert
#include <cstdint> /// for integral typedefs
#include <iostream> /// for io operations
#include <array> // for array
#include <cassert> // for assert
#include <cstdint> // for uint64_t
#include <iostream> // for operator<<, basic_ostream::operator<<, basic_ost...
#include <utility> // for swap
/**
* @namespace data_structures

View File

@@ -1,5 +1,6 @@
#include <iostream>
#include <queue>
#include <cstddef> // for NULL
#include <iostream> // for char_traits, operator<<, basic_ostream, basic_os...
#include <queue> // for queue
/**************************
@author shrutisheoran

View File

@@ -17,9 +17,10 @@
* @author [Pooja](https://github.com/pooja-git11)
* @author [Farbod Ahmadian](https://github.com/farbodahm)
*/
#include <array> /// for std::array
#include <cstdint> /// for integral typedefs
#include <iostream> /// for io operations
#include <stdlib.h> // for exit
#include <array> // for array
#include <cstdint> // for int16_t, int8_t, uint16_t
#include <iostream> // for operator<<, basic_ostream, cout, char_traits
constexpr uint16_t max_size{10}; ///< Maximum size of the queue

View File

@@ -1,4 +1,6 @@
#include <iostream>
#include <cstddef> // for NULL
#include <iostream> // for operator<<, basic_ostream, char_traits, cout
using namespace std;
struct node {

View File

@@ -1,7 +1,8 @@
/*
Write a program to implement Queue using linkedlist.
*/
#include <iostream>
#include <stdlib.h> // for NULL, exit
#include <iostream> // for operator<<, basic_ostream, cout, char_traits
struct linkedlist {
int data;

View File

@@ -5,9 +5,10 @@
* Implementation of a Queue using two Stacks.
*/
#include <cassert>
#include <iostream>
#include <stack>
#include <stdlib.h> // for exit
#include <cassert> // for assert
#include <iostream> // for operator<<, basic_ostream, char_traits, cout, cerr
#include <stack> // for stack
namespace {
/**

View File

@@ -1,505 +1,431 @@
#include<iostream>
#include <cstddef> // for NULL
#include <iostream>
using namespace std;
struct node
{
int key;
node *parent;
char color;
node *left;
node *right;
struct node {
int key;
node *parent;
char color;
node *left;
node *right;
};
class RBtree
{
node *root;
node *q;
public:
RBtree()
{
q = NULL;
root = NULL;
}
void insert();
void insertfix(node *);
void leftrotate(node *);
void rightrotate(node *);
void del();
node* successor(node *);
void delfix(node *);
void disp();
void display(node *);
void search();
class RBtree {
node *root;
node *q;
public:
RBtree() {
q = NULL;
root = NULL;
}
void insert();
void insertfix(node *);
void leftrotate(node *);
void rightrotate(node *);
void del();
node *successor(node *);
void delfix(node *);
void disp();
void display(node *);
void search();
};
void RBtree::insert()
{
int z, i = 0;
cout << "\nEnter key of the node to be inserted: ";
cin >> z;
node *p, *q;
node *t = new node;
t->key = z;
t->left = NULL;
t->right = NULL;
t->color = 'r';
p = root;
q = NULL;
if (root == NULL)
{
root = t;
t->parent = NULL;
}
else
{
while (p != NULL)
{
q = p;
if (p->key < t->key)
p = p->right;
else
p = p->left;
}
t->parent = q;
if (q->key < t->key)
q->right = t;
else
q->left = t;
}
insertfix(t);
void RBtree::insert() {
int z, i = 0;
cout << "\nEnter key of the node to be inserted: ";
cin >> z;
node *p, *q;
node *t = new node;
t->key = z;
t->left = NULL;
t->right = NULL;
t->color = 'r';
p = root;
q = NULL;
if (root == NULL) {
root = t;
t->parent = NULL;
} else {
while (p != NULL) {
q = p;
if (p->key < t->key)
p = p->right;
else
p = p->left;
}
t->parent = q;
if (q->key < t->key)
q->right = t;
else
q->left = t;
}
insertfix(t);
}
void RBtree::insertfix(node *t)
{
node *u;
if (root == t)
{
t->color = 'b';
return;
}
while (t->parent != NULL && t->parent->color == 'r')
{
node *g = t->parent->parent;
if (g->left == t->parent)
{
if (g->right != NULL)
{
u = g->right;
if (u->color == 'r')
{
t->parent->color = 'b';
u->color = 'b';
g->color = 'r';
t = g;
}
}
else
{
if (t->parent->right == t)
{
t = t->parent;
leftrotate(t);
}
t->parent->color = 'b';
g->color = 'r';
rightrotate(g);
}
}
else
{
if (g->left != NULL)
{
u = g->left;
if (u->color == 'r')
{
t->parent->color = 'b';
u->color = 'b';
g->color = 'r';
t = g;
}
}
else
{
if (t->parent->left == t)
{
t = t->parent;
rightrotate(t);
}
t->parent->color = 'b';
g->color = 'r';
leftrotate(g);
}
}
root->color = 'b';
}
void RBtree::insertfix(node *t) {
node *u;
if (root == t) {
t->color = 'b';
return;
}
while (t->parent != NULL && t->parent->color == 'r') {
node *g = t->parent->parent;
if (g->left == t->parent) {
if (g->right != NULL) {
u = g->right;
if (u->color == 'r') {
t->parent->color = 'b';
u->color = 'b';
g->color = 'r';
t = g;
}
} else {
if (t->parent->right == t) {
t = t->parent;
leftrotate(t);
}
t->parent->color = 'b';
g->color = 'r';
rightrotate(g);
}
} else {
if (g->left != NULL) {
u = g->left;
if (u->color == 'r') {
t->parent->color = 'b';
u->color = 'b';
g->color = 'r';
t = g;
}
} else {
if (t->parent->left == t) {
t = t->parent;
rightrotate(t);
}
t->parent->color = 'b';
g->color = 'r';
leftrotate(g);
}
}
root->color = 'b';
}
}
void RBtree::del()
{
if (root == NULL)
{
cout << "\nEmpty Tree.";
return;
}
int x;
cout << "\nEnter the key of the node to be deleted: ";
cin >> x;
node *p;
p = root;
node *y = NULL;
node *q = NULL;
int found = 0;
while (p != NULL && found == 0)
{
if (p->key == x)
found = 1;
if (found == 0)
{
if (p->key < x)
p = p->right;
else
p = p->left;
}
}
if (found == 0)
{
cout << "\nElement Not Found.";
return;
}
else
{
cout << "\nDeleted Element: " << p->key;
cout << "\nColour: ";
if (p->color == 'b')
cout << "Black\n";
else
cout << "Red\n";
void RBtree::del() {
if (root == NULL) {
cout << "\nEmpty Tree.";
return;
}
int x;
cout << "\nEnter the key of the node to be deleted: ";
cin >> x;
node *p;
p = root;
node *y = NULL;
node *q = NULL;
int found = 0;
while (p != NULL && found == 0) {
if (p->key == x)
found = 1;
if (found == 0) {
if (p->key < x)
p = p->right;
else
p = p->left;
}
}
if (found == 0) {
cout << "\nElement Not Found.";
return;
} else {
cout << "\nDeleted Element: " << p->key;
cout << "\nColour: ";
if (p->color == 'b')
cout << "Black\n";
else
cout << "Red\n";
if (p->parent != NULL)
cout << "\nParent: " << p->parent->key;
else
cout << "\nThere is no parent of the node. ";
if (p->right != NULL)
cout << "\nRight Child: " << p->right->key;
else
cout << "\nThere is no right child of the node. ";
if (p->left != NULL)
cout << "\nLeft Child: " << p->left->key;
else
cout << "\nThere is no left child of the node. ";
cout << "\nNode Deleted.";
if (p->left == NULL || p->right == NULL)
y = p;
else
y = successor(p);
if (y->left != NULL)
q = y->left;
else
{
if (y->right != NULL)
q = y->right;
else
q = NULL;
}
if (q != NULL)
q->parent = y->parent;
if (y->parent == NULL)
root = q;
else
{
if (y == y->parent->left)
y->parent->left = q;
else
y->parent->right = q;
}
if (y != p)
{
p->color = y->color;
p->key = y->key;
}
if (y->color == 'b')
delfix(q);
}
if (p->parent != NULL)
cout << "\nParent: " << p->parent->key;
else
cout << "\nThere is no parent of the node. ";
if (p->right != NULL)
cout << "\nRight Child: " << p->right->key;
else
cout << "\nThere is no right child of the node. ";
if (p->left != NULL)
cout << "\nLeft Child: " << p->left->key;
else
cout << "\nThere is no left child of the node. ";
cout << "\nNode Deleted.";
if (p->left == NULL || p->right == NULL)
y = p;
else
y = successor(p);
if (y->left != NULL)
q = y->left;
else {
if (y->right != NULL)
q = y->right;
else
q = NULL;
}
if (q != NULL)
q->parent = y->parent;
if (y->parent == NULL)
root = q;
else {
if (y == y->parent->left)
y->parent->left = q;
else
y->parent->right = q;
}
if (y != p) {
p->color = y->color;
p->key = y->key;
}
if (y->color == 'b')
delfix(q);
}
}
void RBtree::delfix(node *p)
{
node *s;
while (p != root && p->color == 'b')
{
if (p->parent->left == p)
{
s = p->parent->right;
if (s->color == 'r')
{
s->color = 'b';
p->parent->color = 'r';
leftrotate(p->parent);
s = p->parent->right;
}
if (s->right->color == 'b'&&s->left->color == 'b')
{
s->color = 'r';
p = p->parent;
}
else
{
if (s->right->color == 'b')
{
s->left->color = 'b';
s->color = 'r';
rightrotate(s);
s = p->parent->right;
}
s->color = p->parent->color;
p->parent->color = 'b';
s->right->color = 'b';
leftrotate(p->parent);
p = root;
}
}
else
{
s = p->parent->left;
if (s->color == 'r')
{
s->color = 'b';
p->parent->color = 'r';
rightrotate(p->parent);
s = p->parent->left;
}
if (s->left->color == 'b'&&s->right->color == 'b')
{
s->color = 'r';
p = p->parent;
}
else
{
if (s->left->color == 'b')
{
s->right->color = 'b';
s->color = 'r';
leftrotate(s);
s = p->parent->left;
}
s->color = p->parent->color;
p->parent->color = 'b';
s->left->color = 'b';
rightrotate(p->parent);
p = root;
}
}
p->color = 'b';
root->color = 'b';
}
void RBtree::delfix(node *p) {
node *s;
while (p != root && p->color == 'b') {
if (p->parent->left == p) {
s = p->parent->right;
if (s->color == 'r') {
s->color = 'b';
p->parent->color = 'r';
leftrotate(p->parent);
s = p->parent->right;
}
if (s->right->color == 'b' && s->left->color == 'b') {
s->color = 'r';
p = p->parent;
} else {
if (s->right->color == 'b') {
s->left->color = 'b';
s->color = 'r';
rightrotate(s);
s = p->parent->right;
}
s->color = p->parent->color;
p->parent->color = 'b';
s->right->color = 'b';
leftrotate(p->parent);
p = root;
}
} else {
s = p->parent->left;
if (s->color == 'r') {
s->color = 'b';
p->parent->color = 'r';
rightrotate(p->parent);
s = p->parent->left;
}
if (s->left->color == 'b' && s->right->color == 'b') {
s->color = 'r';
p = p->parent;
} else {
if (s->left->color == 'b') {
s->right->color = 'b';
s->color = 'r';
leftrotate(s);
s = p->parent->left;
}
s->color = p->parent->color;
p->parent->color = 'b';
s->left->color = 'b';
rightrotate(p->parent);
p = root;
}
}
p->color = 'b';
root->color = 'b';
}
}
void RBtree::leftrotate(node *p)
{
if (p->right == NULL)
return;
else
{
node *y = p->right;
if (y->left != NULL)
{
p->right = y->left;
y->left->parent = p;
}
else
p->right = NULL;
if (p->parent != NULL)
y->parent = p->parent;
if (p->parent == NULL)
root = y;
else
{
if (p == p->parent->left)
p->parent->left = y;
else
p->parent->right = y;
}
y->left = p;
p->parent = y;
}
void RBtree::leftrotate(node *p) {
if (p->right == NULL)
return;
else {
node *y = p->right;
if (y->left != NULL) {
p->right = y->left;
y->left->parent = p;
} else
p->right = NULL;
if (p->parent != NULL)
y->parent = p->parent;
if (p->parent == NULL)
root = y;
else {
if (p == p->parent->left)
p->parent->left = y;
else
p->parent->right = y;
}
y->left = p;
p->parent = y;
}
}
void RBtree::rightrotate(node *p)
{
if (p->left == NULL)
return;
else
{
node *y = p->left;
if (y->right != NULL)
{
p->left = y->right;
y->right->parent = p;
}
else
p->left = NULL;
if (p->parent != NULL)
y->parent = p->parent;
if (p->parent == NULL)
root = y;
else
{
if (p == p->parent->left)
p->parent->left = y;
else
p->parent->right = y;
}
y->right = p;
p->parent = y;
}
void RBtree::rightrotate(node *p) {
if (p->left == NULL)
return;
else {
node *y = p->left;
if (y->right != NULL) {
p->left = y->right;
y->right->parent = p;
} else
p->left = NULL;
if (p->parent != NULL)
y->parent = p->parent;
if (p->parent == NULL)
root = y;
else {
if (p == p->parent->left)
p->parent->left = y;
else
p->parent->right = y;
}
y->right = p;
p->parent = y;
}
}
node* RBtree::successor(node *p)
{
node *y = NULL;
if (p->left != NULL)
{
y = p->left;
while (y->right != NULL)
y = y->right;
}
else
{
y = p->right;
while (y->left != NULL)
y = y->left;
}
return y;
node *RBtree::successor(node *p) {
node *y = NULL;
if (p->left != NULL) {
y = p->left;
while (y->right != NULL) y = y->right;
} else {
y = p->right;
while (y->left != NULL) y = y->left;
}
return y;
}
void RBtree::disp()
{
display(root);
void RBtree::disp() { display(root); }
void RBtree::display(node *p) {
if (root == NULL) {
cout << "\nEmpty Tree.";
return;
}
if (p != NULL) {
cout << "\n\t NODE: ";
cout << "\n Key: " << p->key;
cout << "\n Colour: ";
if (p->color == 'b')
cout << "Black";
else
cout << "Red";
if (p->parent != NULL)
cout << "\n Parent: " << p->parent->key;
else
cout << "\n There is no parent of the node. ";
if (p->right != NULL)
cout << "\n Right Child: " << p->right->key;
else
cout << "\n There is no right child of the node. ";
if (p->left != NULL)
cout << "\n Left Child: " << p->left->key;
else
cout << "\n There is no left child of the node. ";
cout << endl;
if (p->left) {
cout << "\n\nLeft:\n";
display(p->left);
}
/*else
cout<<"\nNo Left Child.\n";*/
if (p->right) {
cout << "\n\nRight:\n";
display(p->right);
}
/*else
cout<<"\nNo Right Child.\n"*/
}
}
void RBtree::display(node *p)
{
if (root == NULL)
{
cout << "\nEmpty Tree.";
return;
}
if (p != NULL)
{
cout << "\n\t NODE: ";
cout << "\n Key: " << p->key;
cout << "\n Colour: ";
if (p->color == 'b')
cout << "Black";
else
cout << "Red";
if (p->parent != NULL)
cout << "\n Parent: " << p->parent->key;
else
cout << "\n There is no parent of the node. ";
if (p->right != NULL)
cout << "\n Right Child: " << p->right->key;
else
cout << "\n There is no right child of the node. ";
if (p->left != NULL)
cout << "\n Left Child: " << p->left->key;
else
cout << "\n There is no left child of the node. ";
cout << endl;
if (p->left)
{
cout << "\n\nLeft:\n";
display(p->left);
}
/*else
cout<<"\nNo Left Child.\n";*/
if (p->right)
{
cout << "\n\nRight:\n";
display(p->right);
}
/*else
cout<<"\nNo Right Child.\n"*/
}
void RBtree::search() {
if (root == NULL) {
cout << "\nEmpty Tree\n";
return;
}
int x;
cout << "\n Enter key of the node to be searched: ";
cin >> x;
node *p = root;
int found = 0;
while (p != NULL && found == 0) {
if (p->key == x)
found = 1;
if (found == 0) {
if (p->key < x)
p = p->right;
else
p = p->left;
}
}
if (found == 0)
cout << "\nElement Not Found.";
else {
cout << "\n\t FOUND NODE: ";
cout << "\n Key: " << p->key;
cout << "\n Colour: ";
if (p->color == 'b')
cout << "Black";
else
cout << "Red";
if (p->parent != NULL)
cout << "\n Parent: " << p->parent->key;
else
cout << "\n There is no parent of the node. ";
if (p->right != NULL)
cout << "\n Right Child: " << p->right->key;
else
cout << "\n There is no right child of the node. ";
if (p->left != NULL)
cout << "\n Left Child: " << p->left->key;
else
cout << "\n There is no left child of the node. ";
cout << endl;
}
}
void RBtree::search()
{
if (root == NULL)
{
cout << "\nEmpty Tree\n";
return;
}
int x;
cout << "\n Enter key of the node to be searched: ";
cin >> x;
node *p = root;
int found = 0;
while (p != NULL && found == 0)
{
if (p->key == x)
found = 1;
if (found == 0)
{
if (p->key < x)
p = p->right;
else
p = p->left;
}
}
if (found == 0)
cout << "\nElement Not Found.";
else
{
cout << "\n\t FOUND NODE: ";
cout << "\n Key: " << p->key;
cout << "\n Colour: ";
if (p->color == 'b')
cout << "Black";
else
cout << "Red";
if (p->parent != NULL)
cout << "\n Parent: " << p->parent->key;
else
cout << "\n There is no parent of the node. ";
if (p->right != NULL)
cout << "\n Right Child: " << p->right->key;
else
cout << "\n There is no right child of the node. ";
if (p->left != NULL)
cout << "\n Left Child: " << p->left->key;
else
cout << "\n There is no left child of the node. ";
cout << endl;
int main() {
int ch, y = 0;
RBtree obj;
do {
cout << "\n\t RED BLACK TREE ";
cout << "\n 1. Insert in the tree ";
cout << "\n 2. Delete a node from the tree";
cout << "\n 3. Search for an element in the tree";
cout << "\n 4. Display the tree ";
cout << "\n 5. Exit ";
cout << "\nEnter Your Choice: ";
cin >> ch;
switch (ch) {
case 1:
obj.insert();
cout << "\nNode Inserted.\n";
break;
case 2:
obj.del();
break;
case 3:
obj.search();
break;
case 4:
obj.disp();
break;
case 5:
y = 1;
break;
default:
cout << "\nEnter a Valid Choice.";
}
cout << endl;
}
}
int main()
{
int ch, y = 0;
RBtree obj;
do
{
cout << "\n\t RED BLACK TREE ";
cout << "\n 1. Insert in the tree ";
cout << "\n 2. Delete a node from the tree";
cout << "\n 3. Search for an element in the tree";
cout << "\n 4. Display the tree ";
cout << "\n 5. Exit ";
cout << "\nEnter Your Choice: ";
cin >> ch;
switch (ch)
{
case 1: obj.insert();
cout << "\nNode Inserted.\n";
break;
case 2: obj.del();
break;
case 3: obj.search();
break;
case 4: obj.disp();
break;
case 5: y = 1;
break;
default: cout << "\nEnter a Valid Choice.";
}
cout << endl;
} while (y != 1);
return 1;
} while (y != 1);
return 1;
}

View File

@@ -22,9 +22,12 @@
*scenes](https://drive.google.com/file/d/1pM5COF0wx-wermnNy_svtyZquaCUP2xS/view?usp=sharing)
*/
#include <cassert> /// for assert
#include <iostream> /// for I/O operations
#include <new> /// for managing dynamic storage
#include <stdint.h> // for int32_t
#include <stdlib.h> // for exit
#include <cassert> // for assert
#include <iostream> // for char_traits, basic_ostream, operator<<, cerr, cout
#include <new> // for bad_alloc
#include <stdexcept> // for logic_error
/**
* @namespace data_structures

View File

@@ -13,12 +13,12 @@
* @author [Krishna Vedala](https://github.com/kvedala)
*/
#include <array>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <vector>
#include <array> // for array
#include <ctime> // for time
#include <iostream> // for basic_ostream, operator<<, char_traits, cout
#include <memory> // for shared_ptr, __shared_ptr_access, operator!=, ope...
#include <vector> // for vector
#include <cstdlib> // for rand, srand, RAND_MAX
/** \namespace data_structures
* \brief Data-structure algorithms

View File

@@ -22,10 +22,13 @@
* `gcd()`, `lcm()`, and `max()` by changing a few lines of code.
*/
#include <array> /// for std::array
#include <cassert> /// for assert
#include <cstdint> /// for integral typedefs
#include <iostream> /// for IO operations
#include <algorithm> // for copy
#include <array> // for array
#include <cassert> // for assert
#include <cstddef> // for size_t
#include <cstdint> // for int64_t, uint32_t, uint8_t
#include <iostream> // for char_traits, basic_ostream, operator<<, cout, endl
#include <iterator> // for begin, end
/**
* @namespace data_structures

View File

@@ -1,7 +1,8 @@
#include <cassert> /// For std::assert
#include <iostream> /// For std::cout
#include <memory> /// For std::unique_ptr
#include <stdexcept> /// For std::out_of_range
#include <cassert> // for assert
#include <iostream> // for char_traits, basic_ostream, cout, operator<<, endl
#include <memory> // for unique_ptr
#include <stdexcept> // for out_of_range
#include <string> // for basic_string, operator==, string
/**
* @namespace

View File

@@ -8,10 +8,9 @@
* [StudyTonight](https://www.studytonight.com/data-structures/stack-using-queue)
* @author [tushar2407](https://github.com/tushar2407)
*/
#include <cassert> /// for assert
#include <cstdint> /// for integral typedefs
#include <iostream> /// for IO operations
#include <queue> /// for queue data structure
#include <cassert> // for assert
#include <cstdint> // for int64_t, uint32_t
#include <queue> // for queue, swap
/**
* @namespace data_structures

View File

@@ -1,7 +1,10 @@
#include <cassert> /// for assert
#include <iostream> /// for std::cout
#include <cassert> // for assert
#include <iostream> // for operator<<, basic_ostream, cout
#include <memory> // for operator==
#include <stdexcept> // for invalid_argument
#include <vector> // for vector, operator==
#include "./queue.hpp"
#include "./queue.hpp" // for queue
template <typename T>
void testConstructedQueueIsEmpty() {

View File

@@ -1,9 +1,10 @@
#include <cassert> /// for assert
#include <iostream> /// for std::cout
#include <stdexcept> /// std::invalid_argument
#include <vector> /// for std::vector
#include <cassert> // for assert
#include <iostream> // for operator<<, basic_ostream, cout
#include <stdexcept> // for invalid_argument
#include <vector> // for vector, operator==
#include <memory> // for operator==
#include "./stack.hpp"
#include "./stack.hpp" // for stack
template <typename T>
void testConstructedStackIsEmpty() {

View File

@@ -8,14 +8,15 @@
* ./main student.txt
************************************************************
* */
#include <cassert>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <cassert> // for assert
#include <cmath> // for NAN
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
#include <iomanip> // for operator<<, setprecision, _Setprecision
#include <iostream> // for cout
#include <string> // for char_traits, operator>>, basic_string, operat...
#include <memory> // for operator==
#include "./stack.hpp"
#include "./stack.hpp" // for stack
int main(int argc, char* argv[]) {
double GPA = NAN;

View File

@@ -17,10 +17,11 @@
* @author [Kairao ZHENG](https://github.com/fgmn)
*/
#include <array> /// For array
#include <cassert> /// For assert
#include <cstdint> /// for integral typedefs
#include <iostream> /// For IO operations
#include <stdlib.h> // for rand
#include <array> // for array
#include <cassert> // for assert
#include <cstdint> // for INT32_MAX
#include <iostream> // for operator<<, basic_ostream, cout
/**
* @namespace

View File

@@ -1,5 +1,7 @@
#include <iostream>
#include <list>
#include <cstddef> // for NULL
#include <iostream> // for operator<<, basic_ostream, char_traits, cout
#include <list> // for list
using namespace std;
struct node {
@@ -90,30 +92,30 @@ int main() {
cout << "\nEnter Your Choice : ";
cin >> ch;
switch (ch) {
case 1:
int x;
char pos;
cout << "\nEnter the value to be Inserted : ";
cin >> x;
cout << "\nLeft or Right of Root : ";
cin >> pos;
if (pos == 'l')
CreateTree(root, root->left, x, pos);
else if (pos == 'r')
CreateTree(root, root->right, x, pos);
break;
case 2:
BFT(root);
break;
case 3:
Pre(root);
break;
case 4:
In(root);
break;
case 5:
Post(root);
break;
case 1:
int x;
char pos;
cout << "\nEnter the value to be Inserted : ";
cin >> x;
cout << "\nLeft or Right of Root : ";
cin >> pos;
if (pos == 'l')
CreateTree(root, root->left, x, pos);
else if (pos == 'r')
CreateTree(root, root->right, x, pos);
break;
case 2:
BFT(root);
break;
case 3:
Pre(root);
break;
case 4:
In(root);
break;
case 5:
Post(root);
break;
}
} while (ch != 0);
}

View File

@@ -13,13 +13,14 @@ Introduction](https://www.educative.io/page/5689413791121408/80001)
* Other operations should be easy to be added.
* @author [liuhuan](https://github.com/fedom)
*/
#include <array> /// for std::array
#include <cassert> /// for assert
#include <fstream> /// for std::ofstream
#include <iostream> /// for std::cout
#include <memory> /// for std::unique_ptr
#include <queue> /// for std::queue
#include <string> /// for std::to_string
#include <stdint.h> // for int64_t, int8_t, int16_t
#include <array> // for array
#include <cassert> // for assert
#include <fstream> // for basic_ostream, operator<<, basic_ofstream, ofstream
#include <iostream> // for cout
#include <memory> // for allocator, unique_ptr
#include <queue> // for queue
#include <string> // for char_traits, basic_string, operator+, stoi, to_s...
/**
* @namespace data_structures

View File

@@ -4,9 +4,12 @@
* @author Anmol3299
* \brief A basic implementation of trie class to store only lower-case strings.
*/
#include <iostream> // for io operations
#include <memory> // for std::shared_ptr<>
#include <string> // for std::string class
#include <cstddef> // for size_t
#include <iostream> // for basic_ostream, operator<<, cout
#include <memory> // for shared_ptr, __shared_ptr_access, make_shared
#include <stdexcept> // for runtime_error
#include <string> // for basic_string, char_traits, string
#include <utility> // for move
/**
* A basic implementation of trie class to store only lower-case strings.

View File

@@ -7,12 +7,13 @@
* @note the function ::data_structure::trie::deleteString might be erroneous
* @see trie_modern.cpp
*/
#include <array>
#include <cassert>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <stdint.h> // for uint8_t
#include <array> // for array
#include <cassert> // for assert
#include <iostream> // for operator<<, basic_ostream, cout, basic_ostream::...
#include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for char_traits, basic_string, string
#include <cstdlib> // for exit, EXIT_FAILURE
/** \namespace data_structures
* \brief Data-structure algorithms

View File

@@ -10,12 +10,14 @@
* in trie.
* @see trie_modern.cpp for difference
*/
#include <cassert> /// for assert
#include <iostream> /// for IO operations
#include <memory> /// for std::shared_ptr
#include <stack> /// for std::stack
#include <unordered_map> /// for std::unordered_map
#include <vector> /// for std::vector
#include <cassert> // for assert
#include <iostream> // for basic_ostream, operator<<, char_traits, cout
#include <memory> // for shared_ptr, __shared_ptr_access, make_shared
#include <stack> // for stack
#include <unordered_map> // for unordered_map, operator==, _Node_iterator_base
#include <vector> // for vector
#include <string> // for basic_string, string, operator<<
#include <utility> // for pair
/**
* @namespace data_structures