Knowledge in C++

Sorting a Queue without using Extra Space

#include <bits/stdc++.h> using namespace std;    // Queue elements after sortedIndex are  // already sorted. This function returns // index of minimum element from front to // sortedIndex int minIndex(queue<int> &q, int sortedIndex) {     int min_index = -1;     int min_val = INT_MAX;     int n = q.size();     for (int i=0; i<n; i++)     {         int curr = q.front();         q.pop();  // This is dequeue() in C++ STL            // we add the condition i <= sortedIndex         // because we don't want to traverse         // on the sorted part of the queue,         // which is the right part.         if (curr <= min_val && i <= sortedIndex)         {             min_index = i;             min_val = curr;         }         q.push(curr);  // This is enqueue() in                         // C++ STL     }     return min_index; }    // Moves given minimum element to rear of  // queue void insertMinToRear(queue<int> &q, int min_index) {     int min_val;     int n = q.size();     for (int i = 0; i < n; i++)     {         int curr = q.front();         q.pop();         if (i != min_index)             q.push(curr);         else             min_val = curr;     }     q.push(min_val); }    void sortQueue(queue<int> &q) {     for (int i = 1; i <= q.size(); i++)     {         int min_index = minIndex(q, q.size() - i);         insertMinToRear(q, min_index);     } }    // driver code int main() {   queue<int> q;   q.push(30);   q.push(11);   q.push(15);   q.push(4);        // Sort queue   sortQueue(q);        // Print sorted queue   while (q.empty() == false)   {      cout << q.front() << " ";      q.pop();   }   cout << endl;   return 0; }

Subset Backtracking

Subset Backtracking in C

Implement a stack using single Queue

#include<bits/stdc++.h> using namespace std;    // User defined stack that uses a queue class Stack {     queue<int>q; public:     void push(int val);     void pop();     int top();     bool empty(); };    // Push operation void Stack::push(int val) {     //  Get previous size of queue     int s = q.size();        // Push current element     q.push(val);        // Pop (or Dequeue) all previous     // elements and put them after current     // element     for (int i=0; i<s; i++)     {         // this will add front element into         // rear of queue         q.push(q.front());            // this will delete front element         q.pop();     } }    // Removes the top element void Stack::pop() {     if (q.empty())         cout << "No elements\n";     else         q.pop(); }    // Returns top of stack int  Stack::top() {     return (q.empty())? -1 : q.front(); }    // Returns true if Stack is empty else false bool Stack::empty() {     return (q.empty()); }    // Driver code int main() {     Stack s;     s.push(10);     s.push(20);     cout << s.top() << endl;     s.pop();     s.push(30);     s.pop();     cout << s.top() << endl;     return 0; }

Binary Search Tree Non Recursively Program.

A C++ PROGRAM THAT USES FUNCTIONS TO PERFORM THE BINARY SEARCH TREE NON RECURSIVELY.

Binary Search Tree Of Characters Program.

A C++ PROGRAM THAT USES FUNCTIONS TO PERFORM THE FOOLOWING: A.CREATE A BINARY SEARCH TREE OF CHARACTERS. B.TRAVERSE THE ABOVE BINARY SEARCH TREE RECURSIVELY IN PREODER, IN ORDER AND POST ORDER.

Binary Search Tree Of Integers Program.

A C++ PROGRAM THAT USES FUNCTIONS TO PERFORM THE FOLLOWING: A.CREATE A BINARY SEARCH TREE OF INTEGERS. B.TRAVERSE THE ABOVE BINARY SEARCH TREE NON RECURSIVELY IN INORDER.

Binary Search Tree Recursively Program.

A C++ PROGRAM THAT USES FUNCTIONS TO PERFORM THE FOLLOWING: A.CREATE A BINARY SEARCH TREE OF INTEGERS. B.SEARCH FOR AN INTEGER KEY IN THE ABOVE BINARY SEARCH TREE NON RECURSIVELY. C.SEARCH FOR AN INTEGER KEY IN THE ABOVE BINARY SEARCH TREE RECURSIVELY.

Binary Search Program.

A C++ PROGRAM THAT USES FUNCTIONS TEMPLATES TO PERFORM THE SEARCH FOR A KEY ELEMENT IN A LIST OF SEARCH ELEMENTS USING BINARY SEARCH.

Dequeue Linked List Program.

A C++ PROGRAM TO IMPLEMENT A DEQUEUE LINKED LIST USING AN ARRAY, USING A DOUBLY LINKED LIST.

Double Ended Queue Program.

A C++ PROGRAM TO IMPLEMENTS A DOUBLE ENDED QUEUE ADT USING AN ARRAY,USING A DOUBLY LINKED LIST.

Doubly Linked List Program.

A TEMPLATE BASED C++ PROGRAM THAT USES FUNCTIONS TO PERFORM THE FOLLOWIG: A.CREATE A DOUBLY LINKED LIST OF ELEMENTS . B.DELETE A GIVEN ELEMENT FROM THE ABOVE DOUBLY LINKED LIST. C.DISPLAY THE CONTENTS OF THA ABOVE LIST AFTER DELETION.

Hashing Function Program.

A C++PROGRAM TO IMPLEMENTS ALL THE FUNCTIONS OF A DICTIONARY(ADT) USING HASHING.