Follow assignment instructions

1 answer below »
Follow assignment instructions
Answered 1 days AfterFeb 04, 2021

Answer To: Follow assignment instructions

Neha answered on Feb 05 2021
138 Votes
Merge Sort using Queue data type
The idea to solve this problem is to hold all the values in a function call s
tack until the whole queue becomes empty. Once the queue becomes empty, we will insert all the held items into it one by one in a sorted manner. The sorted order is very important.
Algorithm:
As soon as we get the item which is present in the function call stack then first, we will calculate the size of the queue and then compare it with the elements of the queue which are present in it. It may have to different cases. If the item which is returned by the function call stack is larger than the front element of the queue, then it will dequeue the front element and enqueue that element into the same queue and the size will be decreased. If the item which is present in the front element is less than the function call stack, then it will enqueue the element in the queue and it will dequeue the remaining elements and enqueue them by decreasing the size and it will repeat the case one and 2 until the size of the queue becomes zero. One important thing to be noted is that if the size becomes...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here