Go to the previous, next section.
#include <nihcl/LinkedList.h>
Class
LinkedList
provides a linked list data structure with a single forward link. Each object in a
LinkedList
must be an instance of a derived class of class
Link
. A user may implement such a class, or use class
LinkOb
to place object pointers on a
LinkedList
.
LinkedList()
LinkedList
.
virtual Object* add(Link&
lnk)
virtual Object* add(Object&
lnk)
virtual Object* addLast(Link&
lnk)
virtual Object* addLast(Object&
lnk)
Link
, to the end of this
LinkedList
, sets the forward pointer of
lnk
to point to a special
nilLink
, and returns a pointer to
lnk. An
NIHCL_DBLLNK
exception is raised if
lnk
is already linked to another
LinkedList
; i.e., the forward pointer of
lnk
is not 0.
virtual Object* addAfter(Link&
afterLink, Link&
newLink)
virtual Object* addAfter(Object&
afterLink, Object&
newLink)
LinkedList
by inserting it after
afterLink. Both
afterLink
and
newLink
must be derived from class
Link
. An
NIHCL_DBLLNK
exception is raised if
newlnk
is already linked to another
LinkedList
; i.e., the forward pointer of
newlnk
is not 0. A
NIHCL_MISSINGLNK
exception is raised if
afterLink
is
not
on a
LinkedList
; i.e., the forward pointer of
afterLink
is 0 or the size of this
LinkedList
is zero. Note that
afterLink
is not checked to verify that it is linked to this
LinkedList
---the size of the wrong
LinkedList
will be incremented if it is not.
virtual Collection& addContentsTo(Collection&
cltn) const
LinkedList
to
cltn
and returns a reference to
cltn. Links are copied by applying
copy()
.
virtual Object* addFirst(Link&
lnk)
virtual Object* addFirst(Object&
lnk)
Link
, to the beginning of this
LinkedList
, and returns a pointer to
lnk. An
NIHCL_DBLLNK
exception is raised if
lnk
is already linked to another
LinkedList
; i.e., the forward pointer of
lnk
is not 0.
virtual Object* remove(const Link&
lnk)
virtual Object* remove(const Object&
lnk)
LinkedList
for
lnk, which must be a derived class of
Link
, unlink it, and returns a pointer to it. Note that the link removed is the same (i.e.
isSame()
) as
lnk. If this
LinkedList
is empty, an
NIHCL_CLTNEMPTY
exception results, and if
lnk
is not on this
LinkedList
an
NIHCL_OBNOTFOUND
exception is raised.
virtual void removeAll()
LinkedList
.
virtual Object* removeFirst()
virtual Object* removeLast()
LinkedList
and returns a pointer to it. Raises an
NIHCL_CLTNEMPTY
exception if this
LinkedList
is empty. Note that removing the last link requires traversing all the links on a
LinkedList
.
virtual unsigned hash() const
Set
can use as a hash table probe. Class
LinkedList
implements
hash()
by exclusive ORing the results of applying
hash()
to all objects on the
LinkedList
.
virtual int indexOf(const Object&
lnk) const
Link
on this
LinkedList
that
isEqual()
to
lnk. If no equal link is found a -1 is returned.
virtual unsigned occurrencesOf(const Object&
lnk) const
Link
objects on this
LinkedList
that are
isEqual()
to
lnk.
bool operator==(const LinkedList&) const
bool operator!=(const LinkedList&) const
YES
if the left
LinkedList
operand is equal to (or not equal to) the right
LinkedList
operand.
virtual bool includes(const Object&
ob) const
YES
if a link that is
isEqual()
to
ob
is linked on this
LinkedList
.
virtual bool isEmpty() const
YES
if this
LinkedList
is empty.
virtual bool isEqual(const Object&
lnklst) const
YES
if
lnklst
has species
LinkedList
, this
LinkedList
and
lnklst
are the same size, and all corresponding objects are equal, as determined by application of
isEqual()
to each of them.
virtual void deepenShallowCopy()
LinkedList
, applying
deepCopy()
to all links, and adding the copies to create a new
LinkedList
from the copies.
Object* operator[](int i)
const Object *const operator[](int
i) const
Link
on this
LinkedList
.
LinkedList
s are indexed beginning at 0. Raises an
NIHCL_INDEXRANGE
exception if
i
is out of range.
virtual Object* first() const
virtual Object* last() const
Link
in this
LinkedList
. If this
LinkedList
is empty, an
NIHCL_CLTNEMPTY
error is raised.
virtual unsigned capacity() const
virtual unsigned size() const
Link
objects on this
LinkedList
.
virtual void reSize(unsigned
newSize)
LinkedList
.
virtual Object* doNext(Iterator&
pos) const
LinkedList
, or 0 if no more links remain. The
Iterator
argument
pos
maintains the current position in the
LinkedList
.
virtual const Class* species() const
LinkedList
.
virtual Link& linkCastdown(Object&
lnk) const
Link* linkCastdown(Object*
lnk) const
Link::castdown()
to convert the reference (or pointer) to
lnk
to a reference (or pointer) of type
Link&
(or
Link*
). Derived classes must override the definition of
linkCastdown()
to perform a downward cast to a subtype of
Link
, when adding objects to a
LinkedList
that are multiply derived from class
Link
, since the downward cast is otherwise ambiguous. [Section 13.10.5]
virtual void storer(OIOofd&
fd) const
virtual void storer(OIOout&
strm) const
LinkedList
to
fd
or
strm
by applying
storeOn()
to each of them.
virtual Object*& at(int
i)
virtual const Object *const& at(int
i) const
virtual void atAllPut(Object&
ob)
virtual int indexOfSubCollection(const SeqCltn&
cltn, int
start
=0) const
virtual void replaceFrom(int
start, int
stop, const SeqCltn&
replacement, int
startAt
=0)
shouldNotImplement()
.
NIHCL_DBLLNK
,
NIHCL_CLTNEMPTY
,
NIHCL_MISSINGLNK
,
NIHCL_OBNOTFOUND
,
NIHCL_INDEXRANGE
Go to the previous, next section.