Ask Question
1 March, 20:49

In the lab Array Based Queue. The lab calls for implementing a queue using an array such that the queue wraps around to reuse empty array slots. This means that the Head and Tail of the array can reverse relative positions. If, rather than changing the value of the Head and Tail, a modulus (of the size of the array) was used instead, what boundary condition could eventually be reached?

+3
Answers (1)
  1. 1 March, 21:31
    0
    rear = rear+1%n;

    Explanation:

    rear = rear+1%n;

    Where n is the size of the queue.

    Modulus returns the remainder of the two operands. For example, 4%2=0 since 4/2=2 with no remainder, while 4%3=1 since 4/3=1 with remainder 1. Since you can never have a remainder higher than the right operand, you have an effective "range" of answers for any modulus of 0 to (n-1).

    With that in mind, just plug in the numbers for the variables ((4+1) %5=? and (1+1) %4=?). Usually to find the remainder you would use long division, but one useful thing to remember is that any number divided by itself has a remainder of 0, and any number divided by a larger number will have a remainder equal to itself.

    Hence the boundary condition achieved is when at given position there is already an element which is present hence it will break the loop and element would not be ensued until position is free.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “In the lab Array Based Queue. The lab calls for implementing a queue using an array such that the queue wraps around to reuse empty array ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers