Question

In: Computer Science

Suppose we want to make a 10 item queue starting from location x4000. In class, we...

Suppose we want to make a 10 item queue starting from location x4000. In class, we discussed using a HEAD and a TAIL pointer to keep track of the beginning and end of the queue. In fact, we suggested that the HEAD pointer could point to the first element that we would remove from the queue and the TAIL pointer could point the last element that we have added the queue. It turns out that our suggestion does not work.

Part a) What is wrong with our suggestion? (Hint: how do we check if the queue is full? How do we check if it is empty?)

Part b) What simple change could be made to our queue to resolve this problem?

Part c) Using your correction, write a few instructions that check if the queue is full. Use R3 for the HEAD pointer and R4 for the TAIL pointer.

Part d) Using your correction, write a few instructions that check if the queue is empty. Again, using R3 for the HEAD pointer and R4 for the TAIL pointer.

Solutions

Expert Solution

Part(A)

I think something wrong in you suggestion if you De-queue any element you just remove the link but the data are present in the memory .we don't have any better track which helping us for traversal and check that empty/full.

Part(B)

Before en-queue the element you need to check first the queue is not full and also before de-queue element check queue is not empty.(You may use circular Queue for better performance)

NOTE: you can interduce the element size and cap which tell us the queue is full or not

Part(C)

After the value inserted one after the other and check queue is full you can check that by match the address of your tail address with the queue array last index Address and head point to the first location of the array if they equal queue is full,

if(R3==R4&cap>=size)

return 1;

else

return 0;

Part(D)

Initially, the head and the tail pointers will be pointing to the same location, this would mean that the queue is empty.

you can check by comparing the pointing address of head and tail

if(R3==R4&cap<size)

return 1;

else

return 0;


Related Solutions

Say that we want to maintain both a Queue and a Priority Queue. This means that...
Say that we want to maintain both a Queue and a Priority Queue. This means that when you do Enqueue you also add the item to the Priority Queue and when you do Dequeue you also remove the item from the Priority Queue. And vise-versa. Show how to do it. Write pseudo codes or explain in words and the running time.
/* *       Suppose we want to implement a class IntArraySet. The difference of this...
/* *       Suppose we want to implement a class IntArraySet. The difference of this class from IntArrayBag is that each item can only occur once in the set We will use the same instance variables. */ public class IntArraySet { private int[ ] data; private int manyItems; public IntArraySet() { this(10); } public IntArraySet(int initialCapacity) { if (initialCapacity < 0) throw new IllegalArgumentException ("The initialCapacity is negative: " + initialCapacity); data = new int[initialCapacity]; manyItems = 0; }...
Delete an item from a circular queue and return the index of the next item. (in...
Delete an item from a circular queue and return the index of the next item. (in Java)
In C++ In this lab we will be creating a stack class and a queue class,...
In C++ In this lab we will be creating a stack class and a queue class, both with a hybrid method combining linked list and arrays in addition to the Stack methods(push, pop, peek, isEmpty, size, print) and Queue methods (enqueue, deque, peek, isEmpty, size, print). DO NOT USE ANY LIBRARY, implement each method from scratch. Both the Stack and Queue classes should be generic classes. Don't forget to comment your code.
Add a method to OurQueue class that dequeues the Nth item on a queue and returns...
Add a method to OurQueue class that dequeues the Nth item on a queue and returns it. It must remove the Nth item from the Queue but leave the rest of the queue. Test it with the following code: Console.WriteLine("Testing DequeueNth"); OurQueue<string> ourQ = new OurQueue<string>(12); // Empty Q try { ourQ.DequeueNth(0); Console.WriteLine("\a Error on empty list"); } catch { Console.WriteLine("Empty Queue worked"); } for (int i = 0; i < 9; ++i) ourQ.Enqueue("a" + i); for (int i =...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue class . Call your class Queue. it must be a template class. public class Queue <T>{ } I have put a driver program in the module . It is called CircularQueue.java This driver program should then run with your Queue class (no modifications allowed to the driver program). Your Queue class should have at least the following methods: one or more constructors, enqueue, dequeue,...
assume that the standard deviation of exam scores for a class is 10. We want to...
assume that the standard deviation of exam scores for a class is 10. We want to compare scores between two lab sections. How many exams to detect a mean difference of 10 points between the sections? Solve the problem using power approach(type two error)
IN JAVA: Delete an item from a circular queue and return the index of the next...
IN JAVA: Delete an item from a circular queue and return the index of the next item
-If we assume we place the following MIPS code starting at location 8000 in memory, what...
-If we assume we place the following MIPS code starting at location 8000 in memory, what is the MIPS machine code for this code? Show the machine codes in decimal. Please explain each instruction and specify its type ( R format, I format, or J format). k corresponds to register $s4, j corresponds to register $s1, i corresponds to register $s0, and the base of the array v is in $a0 addi $s1,$s0,-1 label2: slti $t0, $s1, 0 bne $t0,...
Suppose we want to assess the effect of a one-day SAT prep class at a 5%...
Suppose we want to assess the effect of a one-day SAT prep class at a 5% level of significance. Scores on the SAT writing exam can range from 200 to 800. A random sample of 50 students takes the SAT writing test before and after a prep class. We test the hypotheses: LaTeX: H_0 H 0 : LaTeX: \mu=0 μ = 0 LaTeX: H_a H a : LaTeX: \mu>0 μ > 0 where LaTeX: \mu μ is the mean of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT