Knowledge in data strcutures

Python Career Path

An comprehensive guide for career options with Python Programming Language. Learn Python Programming now and boost up your career ! For FREE Video Course visit :- https://www.edyoda.com/course/98

Double Ended Queue

# include&lt;stdio.h&gt; #include&lt;process.h&gt; #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(&amp;q); do { printf(&quot;\n1.Create\n2.Insert(rear)\n3.Insert(front)\n4.Delete(rear)\n5.Delete(front)&quot;); printf(&quot;\n6.Print\n7.Exit\n\nEnter your choice:&quot;); scanf(&quot;%d&quot;,&amp;op); switch(op) { case 1: printf(&quot;\nEnter number of elements:&quot;); scanf(&quot;%d&quot;,&amp;n); initialize(&amp;q); printf(&quot;\nEnter the data:&quot;); for(i=0;i&lt;n;i++) { scanf(&quot;%d&quot;,&amp;x); if(full(&amp;q)) { printf(&quot;\nQueue is full!!&quot;); exit(0); } enqueueR(&amp;q,x); } break; case 2: printf(&quot;\nEnter element to be inserted:&quot;); scanf(&quot;%d&quot;,&amp;x); if(full(&amp;q)) { printf(&quot;\nQueue is full!!&quot;); exit(0); } enqueueR(&amp;q,x); break; case 3: printf(&quot;\nEnter the element to be inserted:&quot;); scanf(&quot;%d&quot;,&amp;x); if(full(&amp;q)) { printf(&quot;\nQueue is full!!&quot;); exit(0); } enqueueF(&amp;q,x); break; case 4: if(empty(&amp;q)) { printf(&quot;\nQueue is empty!!&quot;); exit(0); } x=dequeueR(&amp;q); printf(&quot;\nElement deleted is %d\n&quot;,x); break; case 5: if(empty(&amp;q)) { printf(&quot;\nQueue is empty!!&quot;); exit(0); } x=dequeueF(&amp;q); printf(&quot;\nElement deleted is %d\n&quot;,x); break; case 6: print(&amp;q); break; default: break; } }while(op!=7); } void initialize(dequeue *P) { P-&gt;rear=-1; P-&gt;front=-1; } int empty(dequeue *P) { if(P-&gt;rear==-1) return(1); return(0); } int full(dequeue *P) { if((P-&gt;rear+1)%MAX==P-&gt;front) return(1); return(0); } void enqueueR(dequeue *P,int x) { if(empty(P)) { P-&gt;rear=0; P-&gt;front=0; P-&gt;data[0]=x; } else { P-&gt;rear=(P-&gt;rear+1)%MAX; P-&gt;data[P-&gt;rear]=x; } } void enqueueF(dequeue *P,int x) { if(empty(P)) { P-&gt;rear=0; P-&gt;front=0; P-&gt;data[0]=x; } else { P-&gt;front=(P-&gt;front-1+MAX)%MAX; P-&gt;data[P-&gt;front]=x; } } int dequeueF(dequeue *P) { int x; x=P-&gt;data[P-&gt;front]; if(P-&gt;rear==P-&gt;front) //delete the last element initialize(P); else P-&gt;front=(P-&gt;front+1)%MAX; return(x); } int dequeueR(dequeue *P) { int x; x=P-&gt;data[P-&gt;rear]; if(P-&gt;rear==P-&gt;front) initialize(P); else P-&gt;rear=(P-&gt;rear-1+MAX)%MAX; return(x); } void print(dequeue *P) { if(empty(P)) { printf(&quot;\nQueue is empty!!&quot;); exit(0); } int i; i=P-&gt;front; while(i!=P-&gt;rear) { printf(&quot;\n%d&quot;,P-&gt;data[i]); i=(i+1)%MAX; } printf(&quot;\n%d\n&quot;,P-&gt;data[P-&gt;rear]); }

Learn C programming

Hey, in case you are looking for a good C programming tutorial, then you are at correct place.&nbsp; I am going to start C programming tutorial for all who want to learn. Starting from very basic to advanced topics in C will be covered in this tutorial. So, we will start from very basic topics like a variable, data type, and all these things then we will move towards array, functions, strings etc. After that, we will move to data-structures. So, it&#39;s going to be very excited and the teaching technique is going to be unique. Hope, you will enjoy this course. It&#39;s completely free of cost. So, don&#39;t miss this opportunity. See you soon.

BFS tree

#include&lt;iostream&gt; #include &lt;list&gt; &nbsp;&nbsp; using namespace std; &nbsp;&nbsp; // This class represents a directed graph using // adjacency list representation class Graph { &nbsp;&nbsp;&nbsp;&nbsp;int V;&nbsp;&nbsp;&nbsp; // No. of vertices &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;// Pointer to an array containing adjacency &nbsp;&nbsp;&nbsp;&nbsp;// lists &nbsp;&nbsp;&nbsp;&nbsp;list&lt;int&gt; *adj;&nbsp;&nbsp;&nbsp; public: &nbsp;&nbsp;&nbsp;&nbsp;Graph(int V);&nbsp; // Constructor &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;// function to add an edge to graph &nbsp;&nbsp;&nbsp;&nbsp;void addEdge(int v, int w);&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;// prints BFS traversal from a given source s &nbsp;&nbsp;&nbsp;&nbsp;void BFS(int s);&nbsp;&nbsp; }; &nbsp;&nbsp; Graph::Graph(int V) { &nbsp;&nbsp;&nbsp;&nbsp;this-&gt;V = V; &nbsp;&nbsp;&nbsp;&nbsp;adj = new list&lt;int&gt;[V]; } &nbsp;&nbsp; void Graph::addEdge(int v, int w) { &nbsp;&nbsp;&nbsp;&nbsp;adj[v].push_back(w); // Add w to v&rsquo;s list. } &nbsp;&nbsp; void Graph::BFS(int s) { &nbsp;&nbsp;&nbsp;&nbsp;// Mark all the vertices as not visited &nbsp;&nbsp;&nbsp;&nbsp;bool *visited = new bool[V]; &nbsp;&nbsp;&nbsp;&nbsp;for(int i = 0; i &lt; V; i++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;visited[i] = false; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;// Create a queue for BFS &nbsp;&nbsp;&nbsp;&nbsp;list&lt;int&gt; queue; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;// Mark the current node as visited and enqueue it &nbsp;&nbsp;&nbsp;&nbsp;visited[s] = true; &nbsp;&nbsp;&nbsp;&nbsp;queue.push_back(s); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;// &#39;i&#39; will be used to get all adjacent &nbsp;&nbsp;&nbsp;&nbsp;// vertices of a vertex &nbsp;&nbsp;&nbsp;&nbsp;list&lt;int&gt;::iterator i; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;while(!queue.empty()) &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Dequeue a vertex from queue and print it &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s = queue.front(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; s &lt;&lt; &quot; &quot;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queue.pop_front(); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get all adjacent vertices of the dequeued &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// vertex s. If a adjacent has not been visited,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// then mark it visited and enqueue it &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (i = adj[s].begin(); i != adj[s].end(); ++i) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!visited[*i]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;visited[*i] = true; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queue.push_back(*i); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;} }

FIFO using JAVA

import java.util.LinkedList; import java.util.Queue; &nbsp;&nbsp; public class QueueExample { &nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args) &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Queue&lt;Integer&gt; q = new LinkedList&lt;&gt;(); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Adds elements {0, 1, 2, 3, 4} to queue &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; 5; i++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.add(i); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Display contents of the queue. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;Elements of queue-&quot; + q); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// To remove the head of queue. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// In this the oldest element &#39;0&#39; will be removed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int removedele = q.remove(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;removed element-&quot; + removedele); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(q); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// To view the head of queue &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int head = q.peek(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;head of queue-&quot; + head); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Rest all methods of collection interface, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Like size and contains can be used with this &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// implementation. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int size = q.size(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;Size of queue-&quot; + size); &nbsp;&nbsp;&nbsp;&nbsp;} }

Sorting a Queue without using Extra Space

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

Subset Backtracking

Subset Backtracking in C

#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; &nbsp;&nbsp; // Node typedef struct node { &nbsp;&nbsp;&nbsp;&nbsp;int data; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;// Lower values indicate higher priority &nbsp;&nbsp;&nbsp;&nbsp;int priority; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;struct node* next; &nbsp;&nbsp; } Node; &nbsp;&nbsp; // Function to Create A New Node Node* newNode(int d, int p) { &nbsp;&nbsp;&nbsp;&nbsp;Node* temp = (Node*)malloc(sizeof(Node)); &nbsp;&nbsp;&nbsp;&nbsp;temp-&gt;data = d; &nbsp;&nbsp;&nbsp;&nbsp;temp-&gt;priority = p; &nbsp;&nbsp;&nbsp;&nbsp;temp-&gt;next = NULL; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;return temp; } &nbsp;&nbsp; // Return the value at head int peek(Node** head) { &nbsp;&nbsp;&nbsp;&nbsp;return (*head)-&gt;data; } &nbsp;&nbsp; // Removes the element with the // highest priority form the list void pop(Node** head) { &nbsp;&nbsp;&nbsp;&nbsp;Node* temp = *head; &nbsp;&nbsp;&nbsp;&nbsp;(*head) = (*head)-&gt;next; &nbsp;&nbsp;&nbsp;&nbsp;free(temp); } &nbsp;&nbsp; // Function to push according to priority void push(Node** head, int d, int p) { &nbsp;&nbsp;&nbsp;&nbsp;Node* start = (*head); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;// Create new Node &nbsp;&nbsp;&nbsp;&nbsp;Node* temp = newNode(d, p); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;// Special Case: The head of list has lesser &nbsp;&nbsp;&nbsp;&nbsp;// priority than new node. So insert new &nbsp;&nbsp;&nbsp;&nbsp;// node before head node and change head node. &nbsp;&nbsp;&nbsp;&nbsp;if ((*head)-&gt;priority &gt; p) { &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Insert New Node before head &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp-&gt;next = *head; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(*head) = temp; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;else { &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Traverse the list and find a &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// position to insert new node &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (start-&gt;next != NULL &amp;&amp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start-&gt;next-&gt;priority &lt; p) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start = start-&gt;next; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Either at the ends of the list &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// or at required position &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp-&gt;next = start-&gt;next; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start-&gt;next = temp; &nbsp;&nbsp;&nbsp;&nbsp;} } &nbsp;&nbsp; // Function to check is list is empty int isEmpty(Node** head) { &nbsp;&nbsp;&nbsp;&nbsp;return (*head) == NULL; } &nbsp;&nbsp; // Driver code int main() { &nbsp;&nbsp;&nbsp;&nbsp;// Create a Priority Queue &nbsp;&nbsp;&nbsp;&nbsp;// 7-&gt;4-&gt;5-&gt;6 &nbsp;&nbsp;&nbsp;&nbsp;Node* pq = newNode(4, 1); &nbsp;&nbsp;&nbsp;&nbsp;push(&amp;pq, 5, 2); &nbsp;&nbsp;&nbsp;&nbsp;push(&amp;pq, 6, 3); &nbsp;&nbsp;&nbsp;&nbsp;push(&amp;pq, 7, 0); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;while (!isEmpty(&amp;pq)) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;%d &quot;, peek(&amp;pq)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pop(&amp;pq); &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;return 0; }

Implement a stack using single Queue

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

Question papers of DS

Previous year question papers of Datastructure

Stack in Data structures

stact in data structures i.e convert infix expression to postfix using a stack

Data structure using Java.

These are the complete notes of data strucures using java . Chapter wise explanation of all the topics with simple and understandable examples and thier respective java codes.