Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Creates a ListNOde containing value
- *
- * insert the newly created ListNOde at Front of List
- */
- public void addFirst(Object value)
- {
- add(0,value);
- }
- /*
- * return the Object stored in the first ListNOde
- */
- public Object getFirst()
- {
- return get(0);
- }
- /*
- * Creates a ListNOde containing value
- *
- * insert the newly created ListNOde at End of List
- */
- public void addLast(Object value)
- {
- add(size(),value);
- }
- /*
- * return the Object stored in the last ListNOde
- */
- public Object getLast()
- {
- return get(size()-1);
- }
- // return the object previously at index ind.
- // replace that value with obj!
- // preCondition: 0 < ind < size()
- // size() > 0
- public Object set(int ind, Object obj)
- {
- Object o = get(ind);
- getNodeAtIndex(ind).setValue(obj);
- return o;
- }
- /*
- * return a reference to the middle ListNode
- *
- * That is, the Listnode at index = size() / 2 (remember to use integer Math - truncate/round down
- *
- * if size() == 0 return null
- */
- public ListNode getMiddleNode()
- {
- if(size()==0)
- {
- return null;
- }
- int ind = (size()/2);
- return getNodeAtIndex(ind);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement