## Sorting a Queue without Extra Space

In sorting a queue without extra space problem we have given a queue, sort it using standard queue operations without extra space. Examples Input queue = 10 -> 7 -> 2 -> 8 -> 6 Output queue = 2 -> 6 -> 7 -> 8 -> 10 Input queue = …

## Implement Stack using Queues

Implement the following functions of stack data structure using standard operations of queue, push(x) –> Push an element x to the stack pop() –> Removes the element on top of stack top() –> Return the element on top of stack empty() –> Return whether the stack is empty Examples Input: …

## Smallest Multiple of a Given Number

In the smallest multiple of a given number made of digits 0 and 9 only problem we have given a number n, find the smallest number made from digits 0 and 9 that is divisible by n. Assume that the answer will not exceed 106. Examples Input 3 Output 9 …

## Construct Complete Binary Tree from its Linked List Representation

Given the linked list representation of a complete binary tree. The linked list is in the order of level order traversal of the tree. Write an algorithm to construct the complete binary tree back from its linked list representation. Example Input 1 -> 2 -> 3 -> 4 -> 5 …

## Reversing a Queue using Recursion

In reversing a queue using recursion problem we have given a queue, write a recursive algorithm to reverse the queue using recursion. Examples Input 10 -> 9 -> 3 -> 11 -> 5 Output 5 -> 11 -> 3 -> 9 -> 10 Input 1 -> 2 -> 3 -> …

## Queue using Stacks

In queue using a stack problem, we have to implement the following functions of a queue using the standard functions of stack data structure, Enqueue: Add an element to the end of the queue Dequeue: Remove an element from the start of the queue Example Input: Enqueue(5) Enqueue(11) Enqueue(39) Dequeue()  …

## Reversing a Queue

In Reversing a Queue problem we have given a queue, write an algorithm to reverse the queue. Examples Input queue = 10 -> 8 -> 4 -> 23 Output queue = 23->4->8->10 Input queue = 11 -> 98 -> 31 -> 42 -> 73 -> 6 Output queue = 6 …

## How to Implement Stack Using Priority Queue or Heap?

Implement a stack with the help of a priority queue or a heap. Priority Queue : Priority queue data structure is similar to the queue or stack data structure with an addition of priority. Every element is given a priority number. In conclusion, the elements with high priority are prefered …

## Priority Queue in C++

FIFO manner is used to implement a queue. In a queue, insertions are done at one end (rear) and deletion takes place at another end (front). Basically, the element enters first is deleted first. We implement a priority queue using c++ inbuilt functions. Characteristics of Priority Queue A priority queue …

## Priority Queue

A priority queue is a type of data structure which is similar to a regular queue but has a priority associated with each of its element. Higher the priority earlier the element will be served. In some cases, there are two elements with the same priority then, the element enqueued …