public class EmbeddedList
extends Object
remove(Linkable)
to run in constant rather than linear time.Linkable
interface. The easiest way to do this is to simply extend the
LinkableImpl
class, and then no additional work is needed.Modifier and Type | Field and Description |
---|---|
private int |
count
How many objects are currently in the list
|
private Linkable |
head
Reference to the first object in the list, or null if empty
|
private Linkable |
tail
Reference to the last object in the list, or null if empty
|
Constructor and Description |
---|
EmbeddedList() |
Modifier and Type | Method and Description |
---|---|
void |
addHead(Linkable l)
Add an object to the head of the list.
|
void |
addTail(Linkable l)
Add an object to the tail of the list.
|
int |
getCount()
Get a count of the number of objects in the list.
|
Linkable |
getHead()
Get the first object in the list.
|
Linkable |
getTail()
Get the last object in the list.
|
void |
moveToHead(Linkable l)
Move the specified object to the head of the list (if it isn't
already there).
|
void |
moveToTail(Linkable l)
Move the specified object to the tail of the list (if it isn't
already there).
|
Linkable |
remove(Linkable l)
Remove (and return) the specified object from the list.
|
Linkable |
removeHead()
Remove (and return) the first object in the list.
|
Linkable |
removeTail()
Remove (and return) the last object in the list.
|
private Linkable head
private Linkable tail
private int count
public void addHead(Linkable l)
l
- The object to add. Note that it must not be in any other
EmbeddedList.public void addTail(Linkable l)
l
- The object to add. Note that it must not be in any other
EmbeddedList.public Linkable getHead()
public Linkable getTail()
public int getCount()
public Linkable removeHead()
public Linkable removeTail()
public void moveToHead(Linkable l)
public void moveToTail(Linkable l)