Package dsa.iface
Interface IList<T>
- All Known Implementing Classes:
SLinkedList
public interface IList<T>
ADT to represent a List data structure. Also known as a "Sequence" data
structure.
-
Method Summary
Modifier and TypeMethodDescriptionfirst()
Get the first node in the list.insertAfter
(IPosition<T> p, T e) Insert elemente
into the list in the position after nodep
.insertBefore
(IPosition<T> p, T e) Insert elemente
into the list in the position before nodep
.insertFirst
(T e) Insert elemente
as the first element of the list.insertLast
(T e) Insert elemente
as the last element of the list.boolean
isEmpty()
Check if the list is empty.iterator()
Get an iterator that can iterate over the list's elements.last()
Get the last node in the list.Get the node afterp
in the list.Get the node beforep
in the list.Remove nodep
from the list.Replace the element stored in nodep
withe
.int
size()
Get the number of elements in the list.
-
Method Details
-
size
int size()Get the number of elements in the list.- Returns:
-
isEmpty
boolean isEmpty()Check if the list is empty.- Returns:
true
if the list is empty,false
otherwise.
-
first
Get the first node in the list.- Returns:
-
last
Get the last node in the list.- Returns:
-
prev
Get the node beforep
in the list.- Parameters:
p
-- Returns:
-
next
Get the node afterp
in the list.- Parameters:
p
-- Returns:
-
insertFirst
Insert elemente
as the first element of the list. A new node will be created at the start of the list, which will havee
as its element. This node will be placed before any existing first node.- Parameters:
e
-- Returns:
- The node that the new element
e
is stored in.
-
insertLast
Insert elemente
as the last element of the list. A new node will be created at the end of the list, which will havee
as its element. This node will be placed after any existing last node.- Parameters:
e
-- Returns:
- The node that the new element
e
is stored in.
-
insertBefore
Insert elemente
into the list in the position before nodep
. A new node will be created, which will havee
as its element. This node will be placed before nodep
. Ifp
was not the first node in the list, the new node will be placed betweenp
and the node before it.- Parameters:
e
-- Returns:
- The node that the new element
e
is stored in.
-
insertAfter
Insert elemente
into the list in the position after nodep
. A new node will be created, which will havee
as its element. This node will be placed after nodep
. Ifp
was not the last node in the list, the new node will be placed betweenp
and the node after it.- Parameters:
e
-- Returns:
- The node that the new element
e
is stored in.
-
replace
Replace the element stored in nodep
withe
. This does not affect the number of elements in the list.- Parameters:
p
-e
-- Returns:
- The element that was stored in
p
before the replacement.
-
remove
Remove nodep
from the list.- Parameters:
p
-- Returns:
- The element that was stored in
p
.
-
iterator
Get an iterator that can iterate over the list's elements.- Returns:
- The iterator.
-