Question: question: Given class DLNode below make corrections for class NodeDeque if necessary.(ignore line numbers) public class NodeDeque implements Deque header, trailer; l sentinels 8. protected

question: Given class DLNode below make corrections for class NodeDeque if necessary.(ignore line numbers)

 question: Given class DLNode below make corrections for class NodeDeque if

necessary.(ignore line numbers) public class NodeDeque implements Deque header, trailer; l sentinels

8. protected int size; I/ number of elements 9. public NodeDeque0 (

public class NodeDeque implements Deque header, trailer; l sentinels 8. protected int size; I/ number of elements 9. public NodeDeque0 ( linitialize an empty deque 10. header = new DLNode(null, null, null); 11. trailer new DLNode(null, header, null); 12. -header-getviextraiter: make header point to traile 14, size = 0; 15. 16. 17. public int size0 f 18. return size; 19. ) 20. 21. public boolean isEmptyO 22. if(size 0) 23. return true; 24. return false; 25. ) 26. 27. public E getFirst0 throws Empty DequeException if (isEmpty0) 29. throw new EmptyDequeException("Deque is empty."); 30. return header.getNextO.getElementO; 31. 32. 33. public E getLast0 throws EmptyDequeException 34. if (isEmpty0) 35. throw new EmptyDequeException("Deque is empty."); 36. return trailer.getPrevO.getElementO; 37. 38. 39. public void addFirst(E o) f 40. DLNode second header.getNextO; 41. DLNode first-new DLNode(o, header, second); 42. second.setPrev(first); 43. header.setNext(first); 44. size+t; 45. ) 46. 47. public void addLast (E element) 48 DLNode lastsecond trailer.getPrevO: 49. 50. 51. 52. DLNode(element, lastsecond, trailer); lastsecond.setNext(last); trailer.setPrev(last); sizet+ 53. 54. 55. 56. public E removeLast0 throws EmptyDequeException ( 57. if (isEmpty0) 58. throw new EmptyDequeException("Deque is empty."); 59. DLNode last- trailer.getPrev0: 60. Eo last.getElementO; 61. DLNode secondtolast = last.getPrev(); 62. trailer.setPrev(secondtolast); 63. secondtolast.setNext(trailer); 64. Size-- 65. return o; 66. 68. public E removeFirst0 throws EmptyDequeException 69 70. throw new EmptyDequeException("Deque is empty."); 71. DLNode first header.getNextO; 72. 73. 74. 75. 76. if (isEmpty0) E o first.getElementO DLNode E> second first.getNextO; header.setNext(second); second.setPrev(header); size-- 77. return o; 78

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!