Package dsa.lab02.exercises
Class SinglyLinkedList.Node<Item>
java.lang.Object
dsa.lab02.exercises.SinglyLinkedList.Node<Item>
- Type Parameters:
Item- the item type
- All Implemented Interfaces:
LinkedNode<Item>
- Enclosing class:
SinglyLinkedList<Item>
A node in a singly-linked list.
Only holds a direct link to the next node.
-
Constructor Summary
ConstructorsConstructorDescriptionNode(SinglyLinkedList<Item> list, Item item) Construct a node with the given item.Node(SinglyLinkedList<Item> list, Item item, SinglyLinkedList.Node<Item> next) Construct a node with the given item and successor. -
Method Summary
Modifier and TypeMethodDescriptionvoidinsertNext(Item item) Insert a node containing the given item immediately after this one in the list.voidinsertPrevious(Item item) Insert a node containing the given item immediately before this one in the list.item()Get the contained item.list()Get the containing list.next()Get the next node.previous()Get the previous node.remove()Remove the node from the list and return its item.Remove the next node from the list and return its item.Remove the previous node from the list and return its item.voidSet the contained item.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dsa.lab02.base.LinkedNode
hasNext, hasPrevious, isFirst, isLast
-
Constructor Details
-
Node
Construct a node with the given item.- Parameters:
list- the containing linked listitem- the contained item
-
Node
Construct a node with the given item and successor.- Parameters:
list- the containing linked listitem- the contained itemnext- the next node
-
-
Method Details
-
list
Description copied from interface:LinkedNodeGet the containing list.- Specified by:
listin interfaceLinkedNode<Item>- Returns:
- the list
-
item
Description copied from interface:LinkedNodeGet the contained item.- Specified by:
itemin interfaceLinkedNode<Item>- Returns:
- the item
-
setItem
Description copied from interface:LinkedNodeSet the contained item.Replaces whatever was contained before.
- Specified by:
setItemin interfaceLinkedNode<Item>- Parameters:
item- the new item
-
previous
Description copied from interface:LinkedNodeGet the previous node. ornullif this is the first.- Specified by:
previousin interfaceLinkedNode<Item>- Returns:
- the predecessor
-
next
Description copied from interface:LinkedNodeGet the next node. ornullif this is the last.- Specified by:
nextin interfaceLinkedNode<Item>- Returns:
- the successor
-
insertPrevious
Description copied from interface:LinkedNodeInsert a node containing the given item immediately before this one in the list.- Specified by:
insertPreviousin interfaceLinkedNode<Item>- Parameters:
item- the new previous item
-
insertNext
Description copied from interface:LinkedNodeInsert a node containing the given item immediately after this one in the list.- Specified by:
insertNextin interfaceLinkedNode<Item>- Parameters:
item- the new next item
-
remove
Description copied from interface:LinkedNodeRemove the node from the list and return its item.- Specified by:
removein interfaceLinkedNode<Item>- Returns:
- the item
-
removePrevious
Description copied from interface:LinkedNodeRemove the previous node from the list and return its item.- Specified by:
removePreviousin interfaceLinkedNode<Item>- Returns:
- the old previous item
- Throws:
NoSuchElementException- if there is no previous node (i.e. this is the first)
-
removeNext
Description copied from interface:LinkedNodeRemove the next node from the list and return its item.- Specified by:
removeNextin interfaceLinkedNode<Item>- Returns:
- the old next item
- Throws:
NoSuchElementException- if there is no next node (i.e. this is the last)
-