Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. /*
  2. * Creates a ListNOde containing value
  3. *
  4. * insert the newly created ListNOde at Front of List
  5. */
  6. public void addFirst(Object value)
  7. {
  8. add(0,value);
  9. }
  10.  
  11. /*
  12. * return the Object stored in the first ListNOde
  13. */
  14. public Object getFirst()
  15. {
  16. return get(0);
  17. }
  18.  
  19. /*
  20. * Creates a ListNOde containing value
  21. *
  22. * insert the newly created ListNOde at End of List
  23. */
  24. public void addLast(Object value)
  25. {
  26. add(size(),value);
  27. }
  28.  
  29. /*
  30. * return the Object stored in the last ListNOde
  31. */
  32. public Object getLast()
  33. {
  34. return get(size()-1);
  35. }
  36.  
  37. // return the object previously at index ind.
  38. // replace that value with obj!
  39. // preCondition: 0 < ind < size()
  40. // size() > 0
  41. public Object set(int ind, Object obj)
  42. {
  43. Object o = get(ind);
  44. getNodeAtIndex(ind).setValue(obj);
  45. return o;
  46. }
  47.  
  48. /*
  49. * return a reference to the middle ListNode
  50. *
  51. * That is, the Listnode at index = size() / 2 (remember to use integer Math - truncate/round down
  52. *
  53. * if size() == 0 return null
  54. */
  55. public ListNode getMiddleNode()
  56. {
  57. if(size()==0)
  58. {
  59. return null;
  60. }
  61. int ind = (size()/2);
  62. return getNodeAtIndex(ind);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement