s[2];
+ int curr = 0;
+ int oth = 1;
+ s[curr].push(root->data);
+ struct node* temp1 = root;
+ struct node* temp2 = root;
+ while((!s[curr].empty()) || (!s[oth].empty())){
+ if(curr == 0){
+ int p = s[curr].top();
+ s[curr].pop();
+ s[oth].push(temp1->left->data);
+ s[oth].push(temp1->right->data);
+ temp1= temp1->right;
+ cout<right->data);
+ s[curr].push(temp1->left->data);
+ temp1= temp1->left;
+ cout<
+#include
+
+using namespace std;
+
+int main()
+{
+
+struct node{
+ int info;
+ node *next;
+}*ptr,*head,*start;
+
+int c=1,data;
+
+ptr=new node;
+ptr->next=NULL;
+
+start=head=ptr;
+
+while(c<3 && c>0){
+ cout<<"1.Insert\n2.Link List\n";
+ cin>>c;
+
+ switch(c){
+ case 1:
+ cout<<"Enter Data\n";
+ cin>>data;
+
+ ptr=new node;
+ ptr->next=start;
+ ptr->info=data;
+
+ head->next=ptr;
+ head=ptr;
+
+ break;
+
+ case 2:
+ ptr=start->next;
+
+ while(ptr!=start && ptr!=NULL){
+ cout<info<<"->";
+ ptr=ptr->next;
+ }
+ cout<<"\n";
+ break;
+
+ default:
+ cout<<"Wrong Choice\nExiting...\n";
+ }
+
+}
+
+getch();
+return 0;
+}
\ No newline at end of file
diff --git a/algorithms/data-structures/CircularlyLinkedList/CircularlySinglyLinkedList.cpp b/algorithms/data-structures/CircularlyLinkedList/CircularlySinglyLinkedList.cpp
new file mode 100644
index 00000000..1a650c2d
--- /dev/null
+++ b/algorithms/data-structures/CircularlyLinkedList/CircularlySinglyLinkedList.cpp
@@ -0,0 +1,286 @@
+
+#include"CircularlySinglyLinkedList.h"
+
+
+
+template
+void CircularlySinglyLinkedList :: Add_to_empty_list(T val)
+{
+ Node* new_node = new Node(val);
+
+ Tail = new_node;
+ Tail->next = new_node;
+
+Size_++;
+}
+
+
+template
+void CircularlySinglyLinkedList ::Push_back( T val)
+{
+ if(Tail == NULL)
+ {
+ Add_to_empty_list(val);
+
+ }
+ else
+ {
+ Node* new_node = new Node(val);
+ new_node->next = Tail->next;
+ Tail->next = new_node;
+ Tail= new_node;
+ Size_++;
+ }
+}
+
+template
+void CircularlySinglyLinkedList :: Clear()
+{
+
+ if(Size_ == 0 )
+ {
+ cout<<" all cleared linked list is empty"<<'\n';
+ }
+ else
+ {
+ Node* tmp1 = Tail->next;
+ Node* tmp2 = tmp1;
+
+ while(tmp1 != Tail)
+ {
+ tmp1 = tmp1->next;
+ //free the memory of the node to delete it
+ delete tmp2;
+ tmp2=tmp1;
+ }
+ // after the loop we make Tail point to NULL because it points
+ //to a deleted location in the memory (dangling pointer)
+ delete Tail;
+ tmp1 = NULL;
+ tmp2 = NULL;
+ Tail = NULL;
+ Size_ = 0;
+ }
+
+}
+template
+
+void CircularlySinglyLinkedList :: Display()
+{
+ if(Size_ == 0)
+ {
+ cout<<"List is empty"<<'\n';
+ return;
+ }
+ Node* tmp = Tail->next; //Head
+
+ do
+ {
+ cout<data<<" ";
+ tmp = tmp->next;
+
+
+ }
+ while(tmp != Tail->next);
+
+
+
+ cout<<'\n';
+}
+template
+void CircularlySinglyLinkedList :: Pop_back()
+{
+ if( Size_ == 0)
+ {
+ cout<<"Can't pop back. list is empty"<<'\n';
+ return;
+
+ }
+
+ if(Size_ == 1)
+ {
+ delete Tail;
+ Tail = NULL;
+
+
+ }
+ else
+ {
+ Node* tmp = Tail->next;
+
+
+ while(tmp->next != Tail)
+ {
+ tmp = tmp->next;
+ }
+
+ tmp->next = Tail->next;
+ delete Tail;
+ Tail = tmp;
+ }
+
+Size_--;
+}
+
+
+template
+void CircularlySinglyLinkedList :: Push_front(T val)
+{
+ if(Tail == NULL)
+ {
+ Add_to_empty_list(val);
+
+ }
+ else
+ {
+ Node* new_node = new Node(val);
+ new_node->next = Tail->next;
+ Tail->next = new_node;
+ Size_++;
+ }
+
+}
+
+template
+void CircularlySinglyLinkedList :: Pop_front()
+{
+
+ if(Size_ == 0)
+ {
+ cout<<"Can't pop front. List is empty "<<'\n';
+ return;
+ }
+
+
+ if( Size_ == 1)
+ {
+ delete Tail;
+ Tail = NULL;
+
+
+ }
+ else
+ {
+
+ Node* tmp = Tail->next;
+ Tail->next = Tail->next->next;
+ delete tmp;
+
+ }
+
+Size_--;
+
+}
+
+template
+void CircularlySinglyLinkedList :: Insert_at(T val, int position,string afterOrbefore_flag)
+{
+
+
+ if(Size_ == 0)
+ {
+ cout<<"no existing nodes.Linked list is empty. ";
+ return;
+ }
+
+ if(position >Size_ || position < 0)
+ {
+ cout<<"invalid position choose a position between 1 and size "<<'\n';
+ cout<<"size is: "<* tmp;
+ if(afterOrbefore_flag == "before")
+ {
+
+ if(position == 1)
+ {
+ Push_front(val);
+ return;
+
+ }
+ else
+ {
+ tmp=Tail->next;
+ for(int i = 1 ; i next);
+
+ }
+
+
+ }
+ else if(afterOrbefore_flag == "after")
+ {
+
+ if(position == Size_)
+ {
+ Push_back(val);
+ return;
+
+ }
+ else
+ {
+ tmp=Tail->next;
+ for( int i = 1 ; i next);
+
+ }
+
+ }
+
+ Node* new_node = new Node(val);
+ new_node->next = tmp->next;
+ tmp->next = new_node;
+ Size_++;
+
+}
+template
+
+void CircularlySinglyLinkedList :: Delete_at(int position)
+{
+ if(Size_ == 0)
+ {
+ cout<<"no existing nodes.Linked list is empty. ";
+ return;
+ }
+
+ if(position >Size_ || position < 0)
+ {
+ cout<<"invalid position choose a position between 1 and size "<<'\n';
+ cout<<"size is: "<* tmp = Tail->next;
+
+ for(int i = 1 ; i < position-1; i++,tmp = tmp->next);
+
+ Node* node = tmp->next;
+
+ tmp->next = node->next;
+
+ delete node;
+
+
+ Size_--;
+
+ }
+
+
+}
diff --git a/algorithms/data-structures/CircularlyLinkedList/CircularlySinglyLinkedList.h b/algorithms/data-structures/CircularlyLinkedList/CircularlySinglyLinkedList.h
new file mode 100644
index 00000000..fcc4fdbe
--- /dev/null
+++ b/algorithms/data-structures/CircularlyLinkedList/CircularlySinglyLinkedList.h
@@ -0,0 +1,62 @@
+#include
+
+using namespace std;
+
+
+template
+class Node
+{
+ public:
+ T data;
+
+ Node* next;
+
+
+ Node()
+ {
+ next = NULL;
+ }
+
+ Node(T val)
+ {
+ data = val;
+ next = NULL;
+ }
+
+
+
+
+};
+
+template
+class CircularlySinglyLinkedList
+{
+ public:
+
+ Node* Tail;
+ int Size_;
+
+ CircularlySinglyLinkedList()
+ {
+ Size_ = 0;
+ Tail = NULL;
+
+ }
+ void Push_front(T val);
+ void Pop_front();
+ void Push_back(T val);
+ void Pop_back();
+ void Display();
+ void Clear();
+ void Insert_at(T val,int position,string afterOrbefore_flag); // has generalized code for add before node and add after node
+ void Delete_at(int position);
+
+ void Add_to_empty_list(T val);
+
+ ~CircularlySinglyLinkedList()
+ {
+ Clear();
+ }
+
+
+};
diff --git a/algorithms/data-structures/Deque/deque.c b/algorithms/data-structures/Deque/deque.c
new file mode 100644
index 00000000..047cbf9d
--- /dev/null
+++ b/algorithms/data-structures/Deque/deque.c
@@ -0,0 +1,202 @@
+#include
+#include
+#define MAX 30
+
+typedef struct dequeue
+{
+ int data[MAX];
+ int rear,front;
+}dequeue;
+
+void initialize(dequeue *p);
+int empty(dequeue *p);
+int full(dequeue *p);
+void enqueueR(dequeue *p,int x);
+void enqueueF(dequeue *p,int x);
+int dequeueF(dequeue *p);
+int dequeueR(dequeue *p);
+void print(dequeue *p);
+
+void main()
+{
+ int i,x,op,n;
+ dequeue q;
+
+ initialize(&q);
+
+ do
+ {
+ printf("\n1.Create\n2.Insert(rear)\n3.Insert(front)\n4.Delete(rear)\n5.Delete(front)");
+ printf("\n6.Print\n7.Exit\n\nEnter your choice:");
+ scanf("%d",&op);
+
+ switch(op)
+ {
+ case 1: printf("\nEnter number of elements:");
+ scanf("%d",&n);
+ initialize(&q);
+ printf("\nEnter the data:");
+
+ for(i=0;irear=-1;
+ P->front=-1;
+}
+
+int empty(dequeue *P)
+{
+ if(P->rear==-1)
+ return(1);
+
+ return(0);
+}
+
+int full(dequeue *P)
+{
+ if((P->rear+1)%MAX==P->front)
+ return(1);
+
+ return(0);
+}
+
+void enqueueR(dequeue *P,int x)
+{
+ if(empty(P))
+ {
+ P->rear=0;
+ P->front=0;
+ P->data[0]=x;
+ }
+ else
+ {
+ P->rear=(P->rear+1)%MAX;
+ P->data[P->rear]=x;
+ }
+}
+
+void enqueueF(dequeue *P,int x)
+{
+ if(empty(P))
+ {
+ P->rear=0;
+ P->front=0;
+ P->data[0]=x;
+ }
+ else
+ {
+ P->front=(P->front-1+MAX)%MAX;
+ P->data[P->front]=x;
+ }
+}
+
+int dequeueF(dequeue *P)
+{
+ int x;
+
+ x=P->data[P->front];
+
+ if(P->rear==P->front) //delete the last element
+ initialize(P);
+ else
+ P->front=(P->front+1)%MAX;
+
+ return(x);
+}
+
+int dequeueR(dequeue *P)
+{
+ int x;
+
+ x=P->data[P->rear];
+
+ if(P->rear==P->front)
+ initialize(P);
+ else
+ P->rear=(P->rear-1+MAX)%MAX;
+
+ return(x);
+}
+
+void print(dequeue *P)
+{
+ if(empty(P))
+ {
+ printf("\nQueue is empty!!");
+ exit(0);
+ }
+
+ int i;
+ i=P->front;
+
+ while(i!=P->rear)
+ {
+ printf("\n%d",P->data[i]);
+ i=(i+1)%MAX;
+ }
+
+ printf("\n%d\n",P->data[P->rear]);
+}
diff --git a/algorithms/data-structures/DoublyLinkedList/doubly_linked_list.cpp b/algorithms/data-structures/DoublyLinkedList/doubly_linked_list.cpp
new file mode 100644
index 00000000..2808971c
--- /dev/null
+++ b/algorithms/data-structures/DoublyLinkedList/doubly_linked_list.cpp
@@ -0,0 +1,271 @@
+#include"doubly_linked_list.h"
+
+using namespace std;
+
+template
+void DoublyLinkedList :: Push_back(T val)
+{
+
+ auto* new_node = new Node(move(val));
+
+ if(Tail != nullptr) //or if(Size != 0)
+ {
+ Tail->next = new_node;
+ new_node->prev = Tail;
+ Tail = new_node;
+
+ }
+ else
+ {
+ Tail = new_node;
+ Head = new_node;
+ }
+
+ Size_++;
+}
+
+
+template
+void DoublyLinkedList :: Pop_back()
+{
+ //if list is empty
+ if(Tail == nullptr) //or Head == NULL
+ {
+ throw runtime_error("Can't pop back the DLS is empty");
+ }
+
+ if(Tail == Head) // if there's only one element in the DLS
+ {
+ delete Tail;
+ Tail = nullptr;
+ Head = nullptr;
+
+ }
+ else
+ {
+ Node* previous_node = Tail->prev;
+
+ delete Tail;
+
+ Tail = previous_node;
+ Tail->next = nullptr;
+ }
+
+ Size_--;
+
+}
+
+template
+void DoublyLinkedList :: Push_front(T val)
+{
+
+ auto* new_node = new Node(move(val));
+
+ new_node->next = Head;
+ if(Head != nullptr)
+ {
+ Head->prev = new_node;
+
+ }
+ Head = new_node;
+ if(Tail == nullptr)
+ {
+ Tail = Head;
+ }
+
+ Size_++;
+
+}
+
+template
+void DoublyLinkedList :: Pop_front()
+{
+ if(Head == nullptr) //if dls is empty can't pop
+ {
+ throw runtime_error("Can't pop front the DLS is empty");
+ }
+
+ Node* next_node = Head->next;
+ delete Head;
+ Head = next_node;
+
+ if(Head == nullptr) //if we popped the last element
+ {
+ Tail = nullptr;
+ }
+ else
+ {
+ Head->prev = nullptr;
+ }
+
+ Size_--;
+
+}
+
+template
+void DoublyLinkedList :: Add_before(Node* node, T val)
+{
+
+ auto* new_node = new Node(move(val));
+ new_node->next = node;
+ new_node->prev = node->prev;
+ node->prev = new_node;
+
+ if(new_node->prev != nullptr)
+ {
+ new_node->prev->next = new_node;
+ }
+
+ if(Head == node)
+ {
+ Head = new_node;
+
+ }
+ Size_++;
+}
+
+
+
+template
+void DoublyLinkedList :: Add_after(Node* node,T val)
+{
+
+ auto* new_node = new Node(move(val));
+ new_node->prev = node;
+ new_node->next = node->next;
+ node->next = new_node;
+
+
+ if(new_node->next != nullptr)
+ {
+ new_node->next->prev = new_node;
+
+ }
+
+ if(Tail == node)
+ {
+ Tail = new_node;
+ }
+
+ Size_++;
+
+}
+
+template
+void DoublyLinkedList :: Display() const
+{
+
+ if(Size_ == 0)
+ {
+ cout<<"Linked List is empty";
+ }
+ else
+ {
+ for(Node* tmp_ptr = Head;tmp_ptr!= nullptr; tmp_ptr= tmp_ptr->next)
+ {
+ cout<data<<" ";
+
+ }
+ }
+ cout<<'\n';
+}
+
+
+
+template
+void DoublyLinkedList :: Clear()
+{
+
+ Node* tmp = Head;
+ if(Size_ == 0 )
+ {
+ throw runtime_error(" all cleared linked list is empty");
+ }
+
+ while(Head != nullptr)
+ {
+
+ Head = Head->next;
+ delete tmp;
+ tmp = Head;
+
+ }
+ cout<<" all cleared linked list is empty"<<'\n';
+ Tail = nullptr;
+ Size_ = 0;
+}
+template
+void DoublyLinkedList :: Insert_at(T val ,int position)
+{
+ if(position >Size_ || position <= 0)
+ {
+ cout<<"invalid position choose a position between 1 and size "<<'\n';
+ cout<<"size is: "<* tmp = Head;
+ //get a pointer of that position that position
+ for(int i =1 ; i<=position-1 ; i++,tmp = tmp->next);
+ Add_before(tmp,val);
+ }
+
+
+}
+
+template
+void DoublyLinkedList :: Delete_at(int position)
+{
+
+
+ if(Size_ ==0)
+ {
+ cout<<"Can't delete DLS is empty "<<'\n';
+ return;
+ }
+
+ if(position >Size_ || position < 0)
+ {
+ cout<<"invalid position choose a position between 1 and size "<<'\n';
+ cout<<"size is: "<* tmp = Head;
+
+ for(int i = 1; i <= position-1; i++,tmp = tmp->next);
+
+ if(tmp->next != nullptr)
+ {
+ tmp->next->prev = tmp->prev;
+ }
+
+ if(tmp->prev != nullptr)
+ {
+ tmp->prev->next = tmp->next;
+
+ }
+
+ if(Head == tmp)
+ {
+ Head = tmp->next;
+
+ }
+
+ if(Tail == tmp)
+ {
+ Tail = Tail->prev;
+ }
+
+ delete tmp;
+ Size_--;
+
+
+}
+
+
+
diff --git a/algorithms/data-structures/DoublyLinkedList/doubly_linked_list.h b/algorithms/data-structures/DoublyLinkedList/doubly_linked_list.h
new file mode 100644
index 00000000..cf6976f6
--- /dev/null
+++ b/algorithms/data-structures/DoublyLinkedList/doubly_linked_list.h
@@ -0,0 +1,66 @@
+#pragma once
+#include
+
+template
+class Node{
+
+
+ //each node has a next pointer and a previous pinter
+public:
+ T data;
+ Node* next;
+ Node* prev;
+
+
+ Node()
+ {
+ next = nullptr;
+ prev = nullptr;
+
+ }
+
+ explicit Node(T&& value) :
+ data(std::move(value)),
+ next(nullptr),
+ prev(nullptr)
+ {
+ }
+
+};
+
+
+template
+class DoublyLinkedList{
+
+private:
+ Node* Head;
+ Node* Tail;
+ int Size_;
+
+public:
+
+ DoublyLinkedList():
+ Head(nullptr),
+ Tail(nullptr),
+ Size_(0)
+ {
+ }
+
+ void Push_back(T val); //append
+ void Pop_back();
+ void Push_front(T val); //prepend
+ void Pop_front();
+ void Display() const;
+ void Clear();
+ void Insert_at(T val, int position);
+ void Delete_at(int position);
+ void Add_before(Node* node, T val);
+ void Add_after(Node* node,T val);
+
+ ~DoublyLinkedList()
+ {
+ std::cout<<"destructor is called"<<'\n';
+ Clear();
+ }
+
+};
diff --git a/algorithms/data-structures/Doubly_Linked_List.cpp b/algorithms/data-structures/Doubly_Linked_List.cpp
new file mode 100644
index 00000000..782c1b2c
--- /dev/null
+++ b/algorithms/data-structures/Doubly_Linked_List.cpp
@@ -0,0 +1,93 @@
+#include
+#include
+
+using namespace std;
+int main()
+{
+struct node{
+ int info;
+ node *left,*right;
+}*ptr,*start,*last,*save;
+
+int c=1,i=0,data,item;
+start=last=NULL;
+
+while(c<4 && c>0){
+ cout<<"1.Insert\n2.Deletion\n3.Link List\n";
+ cin>>c;
+
+ switch(c){
+ case 1:
+ cout<<"Enter Data\n";
+ cin>>data;
+
+ ptr=new node;
+ ptr->info=data;
+ ptr->left=last;
+ ptr->right=NULL;
+
+ if(start==NULL){
+ start=last=ptr;
+ }
+
+ else{
+ last->right=ptr;
+ last=ptr;
+ }
+ break;
+
+ case 2:
+ if(start==NULL){
+ cout<<"Underflow\n";
+ }
+
+ else{
+ cout<<"Enter Item to be Deleted\n";
+ cin>>item;
+ ptr=start;
+
+ while(ptr!=NULL){
+ if(ptr->info==item){
+ i++;
+ if(ptr==start){
+ start->left=NULL;
+ start=start->right;
+ }
+
+ else{
+ ptr->left->right=ptr->right;
+ ptr->right->left=ptr->left;
+ }
+ delete ptr;
+ cout<<"Item Deleted\n";
+ }
+ ptr=ptr->right;
+ }
+
+ if(i==0){
+ cout<<"Item Does not exist\n";
+ }
+ i=0;
+ }
+ break;
+
+ case 3:
+
+ ptr=start;
+
+ while(ptr!=NULL){
+ cout<info<<"->";
+ ptr=ptr->right;
+ }
+ cout<<"\n";
+ break;
+
+ default:
+ cout<<"Wrong Choice\nExiting...\n";
+ }
+
+}
+
+getch();
+return 0;
+}
\ No newline at end of file
diff --git a/algorithms/data-structures/Find the Unique Element b/algorithms/data-structures/Find the Unique Element
new file mode 100644
index 00000000..ce2a7bd8
--- /dev/null
+++ b/algorithms/data-structures/Find the Unique Element
@@ -0,0 +1,32 @@
+/*
+Given an integer array of size 2N + 1. In this given array,
+N numbers are present twice and one number is present only once in the array.
+You need to find and return that number which is unique in the array.
+*/
+
+#include
+#include
+#include "solution.h"
+using namespace std;
+
+int FindUnique(int arr[], int size){
+ int xor1 = 0;
+ for(int i = 0; i < size; i++)
+ xor1 ^= arr[i];
+ return xor1;
+}
+
+int main() {
+
+ int size;
+
+ cin>>size;
+ int *input=new int[1+size];
+
+ for(int i=0;i>input[i];
+
+ cout<
+using namespace std;
+const int SIZE = 26;
+
+struct MyNode{
+ struct MyNode *children[SIZE];
+ bool isEndOfWord;
+};
+
+// Returns new trie node
+struct MyNode *getNode(void)
+{
+ struct MyNode *pNode = new MyNode;
+
+ pNode->isEndOfWord = false;
+
+ for (int i = 0; i < SIZE; i++)
+ pNode->children[i] = NULL;
+
+ return pNode;
+}
+
+/* If not present, inserts key into trie
+ If the key is prefix of trie node, just
+ marks leaf node*/
+void insert(struct MyNode *root, string key)
+{
+ struct MyNode *pCrawl = root;
+
+ for (int i = 0; i < key.length(); i++)
+ {
+ int index = key[i] - 'a';
+ if (!pCrawl->children[index])
+ pCrawl->children[index] = getNode();
+
+ pCrawl = pCrawl->children[index];
+ }
+
+ // mark last node as leaf
+ pCrawl->isEndOfWord = true;
+}
+
+// Returns true if key presents in trie, else false
+bool search(struct MyNode *root, string key)
+{
+ struct MyNode *pCrawl = root;
+
+ for (int i = 0; i < key.length(); i++)
+ {
+ int index = key[i] - 'a';
+ if (!pCrawl->children[index])
+ return false;
+
+ pCrawl = pCrawl->children[index];
+ }
+
+ return (pCrawl != NULL && pCrawl->isEndOfWord);
+}
+
+// Driver Programme to check above functions
+int main()
+{
+ // For input keys use only lower case
+ string keys[] = {"the", "a", "there",
+ "answer", "any", "by",
+ "bye", "their" };
+ int n = sizeof(keys)/sizeof(keys[0]);
+
+ struct MyNode *root = getNode();
+
+ // Build trie
+ for (int i = 0; i < n; i++)
+ insert(root, keys[i]);
+
+ // Search for different keys to check is it present in our dictonary or not..??
+ search(root, "the")? cout << "Yes\n" : cout << "No\n";
+ search(root, "these")? cout << "Yes\n" : cout << "No\n";
+ return 0;
+}
diff --git a/algorithms/data-structures/avl-tree/AVL.cpp b/algorithms/data-structures/avl-tree/AVL.cpp
new file mode 100644
index 00000000..556e74d3
--- /dev/null
+++ b/algorithms/data-structures/avl-tree/AVL.cpp
@@ -0,0 +1,125 @@
+#include "AVL.h"
+using namespace std;
+
+//Calcule altura de um n
+int height_node(struct _Node_* node){
+ if(node == NULL)
+ return -1;
+ else
+ return node->height;
+}
+//Calcule o fator de balanceamento de um n
+int fatorBalanceamento_node(struct _Node_* node){
+ int valor = (height_node(node->right))-(height_node(node->left));
+ return valor;
+}
+//Calcula o maior valor
+int maior(int x, int y){
+ if(x > y)
+ return x;
+ else
+ return y;
+}
+//Rotao a esquerda
+AVLnode* RotationLL(AVLnode* root){
+ AVLnode*node;
+ node = root->left;
+ root->left = node->right;
+ root->height = maior(height_node(root->left),height_node(root->right)) + 1;
+ node->height = maior(height_node(node->left),height_node(root)) + 1;
+ root = node;
+ return root;
+}
+//Rotao a direita
+AVLnode* RotationRR(AVLnode* root){
+ AVLnode* node;
+ node = root->right;
+ root->right = node->left;
+ root->height = maior(height_node(root->left),height_node(root->right)) + 1;
+ node->height = maior(height_node(node->right),height_node(root)) + 1;
+ root = node;
+ return root;
+}
+//Rotao dupla a esquerda
+AVLnode* RotationLR(AVLnode* root){
+ root->left = RotationRR(root->left);
+ root = RotationLL(root);
+ return root;
+}
+//Rotao dupla a direita
+AVLnode* RotationRL(AVLnode* root){
+ root->right = RotationLL(root->right);
+ root = RotationRR(root);
+ return root;
+}
+//Insert AVLtree
+AVLnode* insert_AVLnode(AVLnode* root,Data* data){
+ //rvore vazia ou n folha
+ if(root == NULL){
+ AVLnode* novo;
+ novo = new AVLnode[1];
+ if(novo == NULL)
+ return NULL;
+ novo->data = data;
+ novo->height = 0;
+ novo->left = NULL;
+ novo->right = NULL;
+ return novo;
+ }
+
+ AVLnode* current = root;
+
+ /*Balaneamento*/
+ if(data->key < current->data->key){
+ current->left = insert_AVLnode(current->left, data);
+ if(current->left != NULL){
+ if(fatorBalanceamento_node(current) <= -2){
+ if(data->key < current->left->data->key)
+ root = RotationLL(root);
+ else
+ root = RotationLR(root);
+ }
+ }
+ return root;
+ }else{
+ if(data->key > current->data->key){
+ current->right = insert_AVLnode(current->right, data);
+ if(current->right != NULL){
+ if(fatorBalanceamento_node(current) >= 2){
+ if(data->key > current->right->data->key)
+ root = RotationRR(root);
+ else
+ root = RotationRL(root);
+ }
+ }
+ }
+ return root;
+ }
+ return NULL;
+}
+//Query
+void Query(AVLnode* root,Data** aux,string str,int* passos){
+ int value = valorString(str);
+ if(root != NULL){
+ if(root->data->key == value){
+ *aux = root->data;
+ }else if(value > root->data->key){
+ Query(root->right, &*aux, str, &*passos);
+ }else{
+ Query(root->left, &*aux, str, &*passos);
+ }
+ }
+ *passos = *passos + 1;
+}
+
+//Destruir
+void Destroy(AVLnode *t){
+ if(t != NULL){
+ Destroy(t->left);
+ Destroy(t->right);
+ t->data->linhas.clear();
+ t->data->ocorrencias.clear();
+ delete[]t->data;
+ delete[]t;
+ }
+}
diff --git a/algorithms/data-structures/avl-tree/AVL.h b/algorithms/data-structures/avl-tree/AVL.h
new file mode 100644
index 00000000..2e22c600
--- /dev/null
+++ b/algorithms/data-structures/avl-tree/AVL.h
@@ -0,0 +1,17 @@
+#ifndef _AVL_H_
+#define _AVL_H_
+#include "structs.h"
+
+typedef struct _Node_{
+ struct _data_ *data;
+ int height;
+ struct _Node_ *left;
+ struct _Node_ *right;
+} AVLnode;
+
+AVLnode* insert_AVLnode(AVLnode* root,Data* data);
+void Query(AVLnode* root,Data** aux,string str, int* passos);
+void Destroy(AVLnode *t);
+
+#endif
+
diff --git a/algorithms/data-structures/binary_search_tree.cpp b/algorithms/data-structures/binary_search_tree.cpp
new file mode 100644
index 00000000..9609c66a
--- /dev/null
+++ b/algorithms/data-structures/binary_search_tree.cpp
@@ -0,0 +1,142 @@
+#include
+#include
+#include
+using namespace std;
+struct tree
+{
+ int value;
+ tree *left;
+ tree *right;
+}*root=NULL;
+void inserte()
+{
+ int v,insert_left=0,insert_right=0;
+ cout<<"Enter Value To Insert: ";
+ cin>>v;
+ tree *newnode=(tree*)malloc(sizeof(tree));
+ newnode->value=v;
+ newnode->left=NULL;
+ newnode->right=NULL;
+ if(root==NULL)
+ root=newnode;
+ else
+ {
+ tree *temp=root;
+ while(1)
+ {
+ if(insert_left==1||insert_right==1)
+ break;
+ if(vvalue)
+ {
+ if(temp->left!=NULL)
+ temp=temp->left;
+ else
+ insert_left=1;
+ }
+ else
+ if(v>temp->value)
+ {
+ if(temp->right!=NULL)
+ temp=temp->right;
+ else
+ insert_right=1;
+ }
+ }
+ if(insert_left==1)
+ temp->left=newnode;
+ else
+ if(insert_right==1)
+ temp->right=newnode;
+ }
+}
+void preorder()
+{
+ tree *temp=root;
+ stack s;
+ repeat:
+ while(1)
+ {
+ if(temp->right!=NULL)
+ s.push(temp->right);
+ if(temp->left!=NULL)
+ {
+ cout<value<<" ";
+ temp=temp->left;
+ }
+ else
+ if(temp->left==NULL)
+ {
+ cout<value<<" ";
+ break;
+ }
+ }
+ while(!s.empty())
+ {
+ temp=s.top();
+ s.pop();
+ goto repeat;
+ }
+}
+void inorder()
+{
+ tree *temp=root;
+ stack s;
+ repeat:
+ while(1)
+ {
+ s.push(temp);
+ if(temp->left!=NULL)
+ temp=temp->left;
+ else
+ break;
+ }
+ while(1)
+ {
+ repeat1:
+ temp=s.top();
+ cout<value<<" ";
+ s.pop();
+ if(temp->right==NULL)
+ goto repeat1;
+ else
+ if(temp->right!=NULL)
+ {
+ temp=temp->right;
+ goto repeat;
+ }
+ else
+ if(s.empty())
+ break;
+ }
+}
+
+int main()
+{
+ int ch;
+ while(1)
+ {
+ cout<>ch;
+ if(ch==1)
+ inserte();
+ else
+ if(ch==2)
+ {
+ preorder();
+ cout<
+#include
+using namespace std;
+
+int lengthOfLongestSubsetWithZeroSum(int* arr, int size){
+ unordered_map mymap;
+ int sum = 0;
+ int maxLength = -1;
+ for(int i = 0; i < size; i++){
+ sum += arr[i];
+ int length = 0;
+
+ if(sum == 0){
+ length = i+1;
+ }else if(mymap.count(sum)){
+ length = i - mymap[sum];
+
+ }else{
+ mymap[sum] = i;
+ }
+
+ if(length > maxLength){
+ maxLength = length;
+ }
+ }
+ return maxLength;
+}
+
+int main(){
+ int size;
+
+ cin >> size;
+ int* arr = new int[size];
+ for(int i = 0; i < size; i++){
+ cin >> arr[i];
+ }
+ int ans = lengthOfLongestSubsetWithZeroSum(arr,size);
+ cout << ans << endl;
+ delete arr;
+}
diff --git a/algorithms/data-structures/largest_rectangle_area.cpp b/algorithms/data-structures/largest_rectangle_area.cpp
new file mode 100644
index 00000000..294b0c4b
--- /dev/null
+++ b/algorithms/data-structures/largest_rectangle_area.cpp
@@ -0,0 +1,61 @@
+/**
+ *
+ *@gaurav yadav
+
+ Maintain a stack
+ a. If stack is empty heights[stack.top()] <= heights[i])
+ push this i into stack.
+ b. Else keep popooing from stack till value at i at top of stack is
+ less than value at current index.
+ c. While popping calculate area
+ if stack is empty
+ area = i * heights[top];
+ it means that till this point value just removed has to be smallest element
+ if stack is not empty
+ area = heights[top] * (i - stack.top() - 1);
+
+ * Finally return maxArea
+ * Time complexity is O(n)
+ * Space complexity is O(n)
+ */
+class Solution {
+public:
+
+ int largestRectangleArea(vector& heights) {
+ int area = 0;
+ int maxArea = 0;
+ stack s;
+ int i;
+ for (i = 0; i < heights.size();) {
+ if (s.empty() || heights[s.top()] <= heights[i]) {
+ s.push(i++);
+ }
+ else {
+ int top = s.top();
+ s.pop();
+ if (s.empty()) {
+ area = i * heights[top];
+ }
+ else {
+ area = heights[top] * (i- s.top() -1);
+ }
+ if (area > maxArea)
+ maxArea = area;
+ }
+ }
+
+ while (!s.empty()) {
+ int top = s.top();
+ s.pop();
+ if (s.empty()) {
+ area = i * heights[top];
+ }
+ else {
+ area = heights[top] * (i- s.top() -1);
+ }
+ if (area > maxArea)
+ maxArea = area;
+ }
+ return maxArea;
+ }
+};
diff --git a/algorithms/data-structures/linkedlist/linkedLists.cpp b/algorithms/data-structures/linkedlist/linkedLists.cpp
new file mode 100644
index 00000000..518031bd
--- /dev/null
+++ b/algorithms/data-structures/linkedlist/linkedLists.cpp
@@ -0,0 +1,151 @@
+#include
+
+using namespace std;
+
+
+
+struct btNode
+{
+ int data;
+ btNode* left;
+ btNode* right;
+};
+
+
+
+
+
+
+void bst_insert(btNode*& bst_root, int anInt)
+{
+ if(bst_root == 0) // if list is empty
+ {
+ btNode* newNode = new btNode;
+
+ newNode->data = anInt;
+ newNode->left = 0;
+ newNode->right= 0;
+
+ bst_root = newNode;
+ return; // end function call
+ }
+
+ btNode* marker = new btNode; // traverse pointer
+ marker = bst_root;
+
+ while( marker != 0) // not at a leaf
+ {
+ if(marker->data == anInt) // if duplicate is found
+ {
+ marker->data = anInt; // overwrite and leave function
+ return;
+ }
+
+
+
+ if(marker->data > anInt) // if # is less than
+ {
+ if(marker->left != 0)
+ {
+ marker = marker->left; // if not empty move left
+ }
+
+ else // if empty, populate
+ {
+ btNode* newNode = new btNode; // create
+
+ newNode->data = anInt; // populate
+ newNode->left = 0;
+ newNode->right = 0;
+
+ marker->left = newNode; // attach
+ return;
+
+ }
+ }
+
+ if(marker->data < anInt) // if # is greater
+ {
+ if(marker->right != 0)
+ marker = marker->right;
+
+ else
+ {
+ btNode* newNode = new btNode;
+
+ newNode->data = anInt;
+ newNode->left = 0;
+ newNode->right = 0;
+
+ marker->right = newNode;
+ return;
+ }
+
+ }
+
+ }
+}
+
+
+ bool bst_remove(btNode*& bst_root, int anInt)
+ {
+
+ if(bst_root == 0) // if empty tree return false
+ return false;
+
+
+ if(bst_root->data > anInt) // if # is less than
+ return bst_remove(bst_root->left,anInt); // shift and recurse
+
+ if(bst_root->data < anInt) // if # is greater than
+ return bst_remove(bst_root->right,anInt);
+
+
+ if(bst_root->data == anInt) // if # is found
+ {
+ if(bst_root->left == 0) // if no left node
+ {
+ btNode* temp = bst_root; //mini remove max
+
+ bst_root = bst_root->right;
+
+ delete temp;
+ return true;
+ }
+
+ // if left node is occupied
+ bst_remove_max(bst_root->left, bst_root->data);
+ return true;
+ }
+
+ return false; // if nothing is found
+
+ }
+
+ void bst_remove_max(btNode*& bst_root, int& info)
+ {
+
+ if(bst_root->right != 0) // if right node is still occupied
+ return bst_remove_max(bst_root->right, info);
+
+
+ btNode* tempNode = new btNode; // prepare node to be deleted
+ tempNode = 0; // make NULL
+
+ btNode* marker = new btNode; // make a node to traverse tree
+ marker = bst_root;
+
+
+ if(bst_root->right == 0) // if at rightmost node
+ {
+ info = bst_root->data; // get information stored in node
+
+ tempNode = marker;
+
+ bst_root = bst_root->left;
+
+ delete tempNode;
+ }
+
+ }
+
diff --git a/algorithms/data-structures/queue/circular_buffer.cpp b/algorithms/data-structures/queue/circular_buffer.cpp
new file mode 100644
index 00000000..dc4e8c54
--- /dev/null
+++ b/algorithms/data-structures/queue/circular_buffer.cpp
@@ -0,0 +1,65 @@
+//
+// Queue: the entities in the collection are kept in
+// order and the principal (or only) operations on the
+// collection are the addition of entities to the rear
+// terminal position
+//
+// The All ▲lgorithms Project
+//
+// https://allalgorithms.com/data-scructures/
+// https://github.com/allalgorithms/cpp
+//
+// Contributed by: Carlos Abraham
+// Github: @abranhe
+//
+#include
+#include
+
+template
+class circular_buffer
+{
+private:
+ T* m_buffer;
+ long m_index;
+
+public:
+ circular_buffer()
+ : m_buffer {new T[SZ]()}
+ , m_index {0}
+ {
+ }
+
+ ~circular_buffer()
+ {
+ delete m_buffer;
+ }
+
+ std::vector get_ordered() noexcept
+ {
+ std::vector vec;
+ for (long i = 0; i < SZ; ++i)
+ vec.push_back(m_buffer[(i + m_index) % SZ]);
+ return vec;
+ }
+
+ void push(T x) noexcept
+ {
+ m_buffer[m_index] = x;
+ m_index = (m_index + 1) % SZ;
+ }
+};
+
+int main()
+{
+ circular_buffer buf;
+
+ buf.push(1);
+ buf.push(2);
+ buf.push(3);
+ buf.push(4);
+ buf.push(5);
+ buf.push(6);
+
+ for (auto x : buf.get_ordered())
+ std::cout << x << std::endl;
+}
diff --git a/algorithms/data-structures/queue/queue.cpp b/algorithms/data-structures/queue/queue.cpp
new file mode 100644
index 00000000..5a07ef27
--- /dev/null
+++ b/algorithms/data-structures/queue/queue.cpp
@@ -0,0 +1,86 @@
+//
+// Queue: the entities in the collection are kept in
+// order and the principal (or only) operations on the
+// collection are the addition of entities to the rear
+// terminal position
+//
+// The All ▲lgorithms Project
+//
+// https://allalgorithms.com/data-scructures/
+// https://github.com/allalgorithms/cpp
+//
+// Contributed by: ANUJ MODI
+// Github: @descifrado
+//
+#include
+#define qsize 5
+struct queue
+{
+ int arr[qsize];
+ int f, r;
+};
+typedef struct queue Queue;
+void
+enqueue (Queue * q, int x)
+{
+ if (q->r == qsize - 1)
+ printf ("QUEUE OVERFLOW\n");
+ else
+ q->arr[++q->r] = x;
+}
+
+int
+dequeue (Queue * q)
+{
+ if (q->f - q->r == 1)
+ printf ("Queue Underflow");
+ else
+ return (q->arr[q->f++]);
+}
+
+int
+main ()
+{
+ Queue q;
+ q.f = 0;
+ q.r = -1;
+ while (1)
+ {
+ printf("Enter 1 to Enqueue\nEnter 2 to Dequeue\nEnter 3 to Display All Elements\nEnter 0 to Exit\n");
+ int c;
+ scanf ("%d", &c);
+ switch (c)
+ {
+ case 0:
+ printf("Ended\n");
+ return 0;
+ case 1:
+ printf ("Enter Element to Enqueue\n");
+ int x;
+ scanf ("%d", &x);
+ enqueue (&q, x);
+ break;
+ case 2:
+ if (q.f - q.r == 1)
+ printf ("Queue Undeflow\n");
+ else
+ printf ("Dequeued Element is %d\n", dequeue (&q));
+ break;
+ case 3:
+ printf ("Elements of Queue Are\n");
+ if (q.f - q.r == 1)
+ {
+ printf ("Queue is Empty\n");
+ break;
+ }
+ int i;
+ for (i = q.f; i <= q.r; i++)
+ printf ("%d ", q.arr[i]);
+ printf ("\n");
+ break;
+ default:
+ printf ("Wrong Choice\n");
+ }
+ }
+ return 0;
+}
diff --git a/algorithms/data-structures/red-black-tree/RedBlack.cpp b/algorithms/data-structures/red-black-tree/RedBlack.cpp
new file mode 100644
index 00000000..2710e388
--- /dev/null
+++ b/algorithms/data-structures/red-black-tree/RedBlack.cpp
@@ -0,0 +1,143 @@
+#include "RedBlack.h"
+
+//Rotao a esquerda
+void rightRotate(RBnode** root, RBnode* x){
+ RBnode* y = x->left;
+ x->left = y->right;
+ if(y->right != NULL)
+ y->right->dad = x;
+ y->dad = x->dad;
+ if (x->dad == NULL){
+ *root = y;
+ }else{
+ if(x == x->dad->right)
+ x->dad->right = y;
+ else
+ x->dad->left = y;
+ }
+ y->right = x;
+ x->dad = y;
+}
+//Rotao a direita
+void leftRotate(RBnode** root,RBnode* x){
+ RBnode* y = x->right;
+ x->right = y->left;
+ if(y->left != NULL)
+ y->left->dad = x;
+ y->dad = x->dad;
+ if(x->dad == NULL)
+ *root = y;
+ else{
+ if(x == x->dad->left)
+ x->dad->left = y;
+ else
+ x->dad->right = y;
+ }
+ y->left = x;
+ x->dad = y;
+}
+
+//color 1-red 0-black
+void fix_insert(RBnode **root, RBnode *node){
+ RBnode* z = node;
+ while((*root != z) && (z->dad->color==1)){
+ if(z->dad == z->dad->dad->left){
+ RBnode* y = z->dad->dad->right;
+ /*Caso 1: Um n x est sendo inserido, e seu tio
+ vermelho ento necessrio recolorir o pai, o tio
+ o av*/
+ if((y!=NULL) && (y->color == 1)){
+ z->dad->color = 0;
+ y->color = 0;
+ z->dad->dad->color = 1;
+ z = z->dad->dad;
+ }else{
+ if(z == z->dad->right){
+ /*Caso 2:irmo preto e pai vermelho*/
+ z = z->dad;
+ leftRotate(&*root,z);
+ }
+ /*Caso 3:pai vermelho, irmo preto, av preto*/
+ z->dad->color = 0;
+ z->dad->dad->color = 1;
+ rightRotate(&*root,z->dad->dad);
+ }
+ }else{
+ RBnode* y = z->dad->dad->left;
+ if((y!=NULL) && (y->color == 1)){
+ /*caso 4*/
+ z->dad->color = 0;
+ y->color = 0;
+ z->dad->dad->color = 1;
+ z = z->dad->dad;
+ }else{
+ /*Caso 5:*/
+ if(z == z->dad->left){
+ z = z->dad;
+ rightRotate(&*root,z);
+ }
+ /*Caso 6:pai vermelho, av preto, tio preto*/
+ z->dad->color = 0;//pai fica preto
+ z->dad->dad->color = 1;//av fica vermelho
+ leftRotate(&*root, z->dad->dad);//gera uma rotao a esquerda
+ }
+ }
+ }
+}
+
+void RB_Insert(RBnode** root, Data* data){
+ RBnode* y = NULL;
+ RBnode* x = *root;
+ while(x != NULL){
+ y = x;
+ if(data->key < x->data->key)
+ x = x->left;
+ else
+ x = x->right;
+ }
+ RBnode* newnode = new RBnode[1];
+ if(newnode != NULL){
+ newnode->data = data;
+ newnode->color = 1;
+ newnode->left = NULL;
+ newnode->right = NULL;
+ newnode->dad = y;
+ }
+ if(y == NULL){
+ *root = newnode;
+ }else{
+ if(data->key < y->data->key)
+ y->left = newnode;
+ else
+ y->right = newnode;
+ }
+ fix_insert(&*root, newnode);
+ (*root)->color = 0;
+}
+
+//Query
+void RBQuery(RBnode* root,Data** aux,string str,int* passos){
+ int value = valorString(str);
+ if(root != NULL){
+ if(root->data->key == value){
+ *aux = root->data;
+ }else if(value > root->data->key){
+ RBQuery(root->right, &*aux, str, &*passos);
+ }else{
+ RBQuery(root->left, &*aux, str, &*passos);
+ }
+ }
+ *passos = *passos+1;
+}
+
+//Destruir
+void RBDestroy(RBnode *t){
+ if(t != NULL){
+ RBDestroy(t->left);
+ RBDestroy(t->right);
+ t->data->linhas.clear();
+ t->data->ocorrencias.clear();
+ delete[]t->data;
+ delete[]t;
+ }
+}
diff --git a/algorithms/data-structures/red-black-tree/RedBlack.h b/algorithms/data-structures/red-black-tree/RedBlack.h
new file mode 100644
index 00000000..d2743f54
--- /dev/null
+++ b/algorithms/data-structures/red-black-tree/RedBlack.h
@@ -0,0 +1,14 @@
+#ifndef _REDBLACK_H_
+#define _REDBLACK_H_
+#include "structs.h"
+
+ typedef struct _RBNode_{
+ int color;
+ struct _data_ *data;
+ struct _RBNode_ *left, *right, *dad;
+ } RBnode;
+
+ extern void RB_Insert(RBnode** root, Data* data);
+ extern void RBQuery(RBnode* root,Data** aux,string str,int* passos);
+ void RBDestroy(RBnode *t);
+#endif
diff --git a/algorithms/data-structures/segment_tree/a.out b/algorithms/data-structures/segment_tree/a.out
new file mode 100755
index 00000000..2aa14deb
Binary files /dev/null and b/algorithms/data-structures/segment_tree/a.out differ
diff --git a/algorithms/data-structures/segment_tree/min_in_range.cpp b/algorithms/data-structures/segment_tree/min_in_range.cpp
new file mode 100644
index 00000000..2a5fcb63
--- /dev/null
+++ b/algorithms/data-structures/segment_tree/min_in_range.cpp
@@ -0,0 +1,98 @@
+//
+// SEGMENT TREE : A Segment Tree is a data structure that allows
+// answering range queries over an array effectively,
+// while still being flexible enough to allow modifying the array.
+//
+// The All ▲lgorithms Project
+//
+// https://allalgorithms.com/data-scructures/
+// https://github.com/allalgorithms/cpp
+//
+// Contributed by: RITUPARNO BISWAS
+// Github: @roopbiswas
+//
+
+
+#include
+using namespace std;
+
+
+int st[400005],a[100005],y,l,r,x;
+
+void build(int in,int s,int e)
+{
+ if(s==e)
+ {
+ st[in]=a[s];
+ return;
+ }
+ int m=(s+e)/2;
+ build(2*in,s,m);
+ build(2*in+1,m+1,e);
+ st[in]= min(st[2*in],st[2*in+1]);
+}
+
+void update(int in,int s,int e)
+{
+ if(s==e)
+ {
+ st[in]=y;
+ return;
+ }
+ int m=(s+e)/2;
+ if(s<=x && x<=m)
+ update(2*in,s,m);
+ else
+ update(2*in+1,m+1,e);
+ st[in]=min(st[2*in],st[2*in+1]);
+}
+
+int query(int in,int s,int e)
+{
+ if(r>n;
+ for(i=0;i>a[i];
+ cin>>t;
+ char ch;
+ build(1,0,n-1);
+ while(t--)
+ {
+ cout<<"Enter choice : \nu : for update\nq : for query\n";
+ cin>>ch;
+
+ if(ch=='u')
+ {
+ cout<<"Enter values of index(1 based) and updated value\n";
+ cin>>x>>y;
+ x--;
+ update(1,0,n-1);
+ }
+ else
+ {
+ cout<<"Enter values(1 based) of upper and lower index\n";
+ cin>>l>>r;
+ l--;
+ r--;
+ cout<<"\nMINIMUM : "<
+using namespace std;
+
+
+int st[400005],a[100005],y,l,r,x;
+
+void build(int in,int s,int e)
+{
+ if(s==e)
+ {
+ st[in]=a[s];
+ return;
+ }
+ int m=(s+e)/2;
+ build(2*in,s,m);
+ build(2*in+1,m+1,e);
+ st[in]= st[2*in]+st[2*in+1];
+}
+
+void update(int in,int s,int e)
+{
+ if(s==e)
+ {
+ st[in]=y;
+ return;
+ }
+ int m=(s+e)/2;
+ if(s<=x && x<=m)
+ update(2*in,s,m);
+ else
+ update(2*in+1,m+1,e);
+ st[in]=st[2*in]+st[2*in+1];
+}
+
+int query(int in,int s,int e)
+{
+ if(r>n;
+ for(i=0;i>a[i];
+ cin>>t;
+ char ch;
+ build(1,0,n-1);
+ while(t--)
+ {
+ cout<<"Enter choice : \nu : for update\nq : for query\n";
+ cin>>ch;
+
+ if(ch=='u')
+ {
+ cout<<"Enter values of index(1 based) and updated value\n";
+ cin>>x>>y;
+ x--;
+ update(1,0,n-1);
+ }
+ else
+ {
+ cout<<"Enter values(1 based) of upper and lower index\n";
+ cin>>l>>r;
+ l--;
+ r--;
+ cout<<"\nSUM : "<
+#include
+
+using namespace std;
+
+//- Global Variable (came from main)!
+struct Node *top = NULL;
+
+struct Node{
+ int data;
+ struct Node *next;
+};
+
+void linkedlistTraversal(struct Node * ptr){
+ while(ptr!=NULL){
+ printf("Element: %d\n", ptr->data);
+ ptr = ptr->next;
+ }
+}
+
+int isEmpty(struct Node* top){
+ if(top == NULL){
+ return 1;
+ }
+ return 0;
+}
+
+int isFull(struct Node* top){
+ struct Node * n = (struct Node *) malloc(sizeof(struct Node));
+ if(n == NULL){
+ return 1;
+ }
+ return 0;
+}
+
+struct Node* push(struct Node* top, int data){
+ if(isFull(top)){
+ printf("Stack Overflow!\n");
+ }
+ else{
+ struct Node * n = (struct Node*) malloc(sizeof(struct Node));
+ n->data = data;
+ n->next = top;
+ top = n;
+ return top;
+ }
+}
+
+int pop(struct Node * tp){
+ if(isEmpty(tp)){
+ printf("Stack Underflow!");
+ }
+ else{
+ struct Node * n = tp;
+ top = (tp)->next;
+ int x = n->data;
+ free(n);
+ return x;
+ }
+}
+
+int peek(int pos){
+ struct Node * ptr = top;
+ for (int i = 0; (i < pos-1 && ptr!=NULL); i++)
+ {
+ ptr = ptr->next;
+ }
+ if(ptr!=NULL){
+ return ptr->data;
+ }
+ else{
+ return -1; // assuming there's no -ve element in stack
+ }
+}
+
+int stackTop(struct Node * top){
+ return top->data;
+}
+
+int stackBottom(struct Node * top){
+ struct Node * p = top;
+ while(p->next!=NULL){
+ p = p->next;
+ }
+ return p->data;
+}
+
+int main()
+{
+ top = push(top, 69);
+ top = push(top, 10);
+ top = push(top, 8);
+ top = push(top, 7);
+ linkedlistTraversal(top);
+
+ for (int i = 1; i <= 4; i++)
+ {
+ printf("The element at position %d is %d\n",i,peek(i));
+ }
+
+ // printf("The top most element in stack is %d\n",stackTop(top));
+ printf("The bottom most element in stack is %d\n",stackBottom(top));
+
+
+
+ return 0;
+}
diff --git a/algorithms/data-structures/stack/stack_using_two_queues.cpp b/algorithms/data-structures/stack/stack_using_two_queues.cpp
new file mode 100644
index 00000000..30443571
--- /dev/null
+++ b/algorithms/data-structures/stack/stack_using_two_queues.cpp
@@ -0,0 +1,66 @@
+#include
+using namespace std;
+
+class QueueStack{
+private:
+ queue q1;
+ queue q2;
+public:
+ void push(int);
+ int pop();
+};
+
+
+int main()
+{
+ int T;
+ cin>>T;
+ while(T--)
+ {
+ QueueStack *qs = new QueueStack();
+
+ int Q;
+ cin>>Q;
+ while(Q--){
+ int QueryType=0;
+ cin>>QueryType;
+ if(QueryType==1)
+ {
+ int a;
+ cin>>a;
+ qs->push(a);
+ }else if(QueryType==2){
+ cout<pop()<<" ";
+
+ }
+ }
+ cout< q1;
+ queue