Package dsa.lab02.solutions
Class DoublyLinkedList.Node<Item>
java.lang.Object
dsa.lab02.solutions.DoublyLinkedList.Node<Item>
- Type Parameters:
Item
- the item type
- All Implemented Interfaces:
LinkedNode<Item>
- Enclosing class:
DoublyLinkedList<Item>
A node in a doubly-linked list.
Holds direct links to both the previous and next nodes.
-
Constructor Summary
ConstructorDescriptionNode
(DoublyLinkedList<Item> list, DoublyLinkedList.Node<Item> previous, Item item) Construct a node with the given predecessor and item.Node
(DoublyLinkedList<Item> list, DoublyLinkedList.Node<Item> previous, Item item, DoublyLinkedList.Node<Item> next) Construct a node with the given predecessor, item and successor.Node
(DoublyLinkedList<Item> list, Item item) Construct a node with the given item.Node
(DoublyLinkedList<Item> list, Item item, DoublyLinkedList.Node<Item> next) Construct a node with the given item and successor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
insertNext
(Item item) Insert a node containing the given item immediately after this one in the list.void
insertPrevious
(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.void
Set the contained item.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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 predecessor and item.- Parameters:
list
- the containing linked listprevious
- the previous nodeitem
- 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
-
Node
public Node(DoublyLinkedList<Item> list, DoublyLinkedList.Node<Item> previous, Item item, DoublyLinkedList.Node<Item> next) Construct a node with the given predecessor, item and successor.- Parameters:
list
- the containing linked listprevious
- the previous nodeitem
- the contained itemnext
- the next node
-
-
Method Details
-
list
Description copied from interface:LinkedNode
Get the containing list.- Specified by:
list
in interfaceLinkedNode<Item>
- Returns:
- the list
-
item
Description copied from interface:LinkedNode
Get the contained item.- Specified by:
item
in interfaceLinkedNode<Item>
- Returns:
- the item
-
setItem
Description copied from interface:LinkedNode
Set the contained item.Replaces whatever was contained before.
- Specified by:
setItem
in interfaceLinkedNode<Item>
- Parameters:
item
- the new item
-
previous
Description copied from interface:LinkedNode
Get the previous node. ornull
if this is the first.- Specified by:
previous
in interfaceLinkedNode<Item>
- Returns:
- the predecessor
-
next
Description copied from interface:LinkedNode
Get the next node. ornull
if this is the last.- Specified by:
next
in interfaceLinkedNode<Item>
- Returns:
- the successor
-
insertPrevious
Description copied from interface:LinkedNode
Insert a node containing the given item immediately before this one in the list.- Specified by:
insertPrevious
in interfaceLinkedNode<Item>
- Parameters:
item
- the new previous item
-
insertNext
Description copied from interface:LinkedNode
Insert a node containing the given item immediately after this one in the list.- Specified by:
insertNext
in interfaceLinkedNode<Item>
- Parameters:
item
- the new next item
-
remove
Description copied from interface:LinkedNode
Remove the node from the list and return its item.- Specified by:
remove
in interfaceLinkedNode<Item>
- Returns:
- the item
-
removePrevious
Description copied from interface:LinkedNode
Remove the previous node from the list and return its item.- Specified by:
removePrevious
in 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:LinkedNode
Remove the next node from the list and return its item.- Specified by:
removeNext
in interfaceLinkedNode<Item>
- Returns:
- the old next item
- Throws:
NoSuchElementException
- if there is no next node (i.e. this is the last)
-