** Data Structures and Algorithms Using Java** a)Give the integer range of the v
ID: 3890311 • Letter: #
Question
** Data Structures and Algorithms Using Java**
a)Give the integer range of the values that rear can assume after the statement:
rear = x % 54; executes (assume x is an integer).
b)Give the line numbers of the code presented in Figure 3.26 (see textbook page 160) that perform the garbage collection for the structure Queue.
1. pub1ic class Queue 2. private Listingl] data; private int size; private int numof Nodes private int front; private int rear 5. 7. public Queue () 0.t1ze 100 numof Nodes o; front 0; rear 0; data new Listing 1001: 12. 13. 14. public Queue(int n) 16. size n 16. 17 front = 0; rear = 0; data new Listingtnl: 19, 20. 21. public boolean enque (Listing newNode) 22. if (numofNodes size) return false;overt low error- 23 24 . 25. 26. 27. 28. 29. 30. 31. public Listing deque() 32. int frontLocation; 33. 34. 35. 36. 37, 38. 39. 40 41. 42. public void showA11() 43. int i front; else { numOf Nodes numOfNodes + 1; datal rear] newMode.deepCopy ( ); rear (rear + 1) % size; return true; push operation successful if ( nunOfNodes 0) = return null; else underflow error { fron t Location= front; front = (front + 1) % size; numOf Nodes nunOf Nodes . 1; return datalfrontLocationl: for (int c 1; c c nunOfNodes; c++ ( System.out.printin(datali].toString(0) 45. 46. 47. 48. 1 end of showAll metnod 49. end of olass Queue i= (i + 1) % size; Figure 3.26 Implementation of a Classical QueueExplanation / Answer
a) x%54 , So x = 0 , 1...53 when x becomes 54 again it boild down to zero
Rear can work with 0-53
b) Line number 33 and 34 ,
Reason: When we call dequeue() we expect some listing data to be retuned, SO when null is retuned that means there is no data so it can be garbage collected.
Thanks, let me know if there is any doubts/concern.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.