|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--LinkdList
LinkdList.java
Illustrates the implementation of a linked list with a null object.
Based on Linked List
Created: Mon Feb 24 21:26:57 2003
Field Summary | |
protected boolean |
empty
|
protected Object |
first
|
protected LinkdList |
rest
|
Constructor Summary | |
LinkdList()
Constructs an empty LinkdList . |
|
LinkdList(Object f,
LinkdList list)
Constructs a LinkdList consisting of an Object
prepended to another list. |
Method Summary | |
boolean |
add(Object o)
Appends the specified element to the end of this list. |
Object |
get(int index)
Returns the element at the specified position in this list, the first element having index == 1. |
Object |
getFirst()
Returns the first element in this list. |
LinkdList |
getRest()
Returns this list omitting the first element. |
LinkdList |
insert(Object obj,
int ndx)
Returns a LinkdList just like this one, but with
obj inserted as the new
ndx th element. |
boolean |
isEmpty()
Returns true if this list contains no elements |
Object |
remove(int index)
Removes the element at the specified position in this list. |
int |
size()
Returns the number of elements in this list. |
String |
toString()
Returns a string representing this list as its elements, separated by commas, surrounded by parentheses. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Object first
protected LinkdList rest
protected boolean empty
Constructor Detail |
public LinkdList()
LinkdList
.
public LinkdList(Object f, LinkdList list)
LinkdList
consisting of an Object
prepended to another list.
f
- the Object
to be the first element of
this list.list
- a LinkdList
to be the
rest
of this list.Method Detail |
public Object getFirst()
NoSuchElementException
- if this list is empty.public LinkdList getRest()
NoSuchElementException
- if this list is empty.public boolean isEmpty()
public Object get(int index) throws IndexOutOfBoundsException
index
- index of element to return.
IndexOutOfBoundsException
- if the specified index is
is out of range (index < 1 || index > size()).public int size()
public boolean add(Object o)
o
- element to be appended to this list.
public Object remove(int index) throws IndexOutOfBoundsException
index
- the index of the element to removed.
IndexOutOfBoundsException
- if the specified index is
out of range (index < 1 || index > size()).public LinkdList insert(Object obj, int ndx)
LinkdList
just like this one, but with
obj
inserted as the new
ndx
th element.
obj
- the Object
to be inserted.ndx
- the new position for obj
.
LinkdList
just like this one, but with
obj
inserted as the new
ndx
th element.
IndexOutOfBoundsException
- if ndx < 1 ||
ndx > this.size()+1
.public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |