Grafalgo
Library of useful data structures and algorithms
|
Data structure representing a list of indexes. More...
#include <List.h>
Public Member Functions | |
List (int=26) | |
Create a list with space for index values in 1..nn1. | |
~List () | |
Destructor for List. | |
void | clear () |
Remove all elements from list. | |
void | resize (int) |
Resize a List object. | |
void | expand (int) |
Expand the space available for this List. | |
void | copyFrom (const List &) |
Copy into list from source. | |
index | get (position) const |
Get an index based on its position in the list. | |
index | next (index) const |
Get the next index in a list. | |
index | first () const |
Get first index on list. | |
index | last () const |
Get the last index on list. | |
int | length () const |
Determine the length of the list. | |
bool | valid (index) const |
Test if a given index is valid for this List. | |
bool | empty () const |
Test if list is empty. | |
bool | member (index) const |
Test if an index is in the list. | |
bool | equals (List &) const |
Compare two lists for equality. | |
bool | isConsistent () const |
Check the data structure for consistency. | |
virtual bool | insert (index, index) |
Insert an index into the list, relative to another. | |
virtual bool | removeNext (index) |
Remove the index following a specified index. | |
bool | addFirst (index) |
Add index to the front of the list. | |
bool | addLast (index) |
Add index to the end of the list. | |
bool | removeFirst () |
Remove the first index in the list. | |
string & | toString (string &) const |
Create a string representation of a given string. | |
Protected Member Functions | |
void | makeSpace (int) |
Allocate and initialize space for list. | |
void | freeSpace () |
Free dynamic storage used by list. | |
Private Attributes | |
int | len |
number of elements in list | |
index | head |
first index in list | |
index | tail |
last index in list | |
index * | nxt |
nxt[i] is successor of i in list | |
Friends | |
istream & | operator>> (istream &, List &) |
Data structure representing a list of indexes.
An index is a postive integer in 1..n where n is an upper bound on the size of the list. An index can appear on a list at most once. Index-based lists are handy in contexts where we need a common "handle" for a piece of data in several different data structures. They are also compact, efficient and support constant-time membership tests (based on the index).
Note: List has several virtual members, insert() and removeNext() to allow facilitate extension by other classes.
grafalgo::List::~List | ( | ) |
bool grafalgo::List::addFirst | ( | index | i | ) | [inline] |
bool grafalgo::List::addLast | ( | index | i | ) | [inline] |
void grafalgo::List::clear | ( | ) | [virtual] |
Remove all elements from list.
Implements grafalgo::Adt.
Definition at line 75 of file List.cpp.
void grafalgo::List::copyFrom | ( | const List & | source | ) |
bool grafalgo::List::empty | ( | ) | const [inline] |
bool grafalgo::List::equals | ( | List & | other | ) | const |
Compare two lists for equality.
other | is the list to be compared to this one |
Definition at line 146 of file List.cpp.
void grafalgo::List::expand | ( | int | size | ) | [virtual] |
Expand the space available for this List.
Rebuilds old value in new space.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Reimplemented in grafalgo::Dlist.
Definition at line 68 of file List.cpp.
index grafalgo::List::first | ( | ) | const [inline] |
void grafalgo::List::freeSpace | ( | ) | [protected] |
Free dynamic storage used by list.
Reimplemented in grafalgo::Dlist.
Definition at line 41 of file List.cpp.
index grafalgo::List::get | ( | position | i | ) | const |
Get an index based on its position in the list.
i | is position of index to be returned; must be between 1 and n() |
Reimplemented in grafalgo::Dlist.
Definition at line 82 of file List.cpp.
bool grafalgo::List::insert | ( | index | i, |
index | j | ||
) | [virtual] |
Insert an index into the list, relative to another.
i | is index to insert; if i is 0 or already in the list, no change is made |
j | is index after which i is to be inserted; if zero, i is inserted at the front of the list |
Reimplemented in grafalgo::Dlist.
Definition at line 97 of file List.cpp.
bool grafalgo::List::isConsistent | ( | ) | const |
index grafalgo::List::last | ( | ) | const [inline] |
int grafalgo::List::length | ( | ) | const [inline] |
void grafalgo::List::makeSpace | ( | int | size | ) | [protected] |
Allocate and initialize space for list.
size | is number of index values to provide space for |
Reimplemented in grafalgo::Dlist.
Definition at line 27 of file List.cpp.
bool grafalgo::List::member | ( | index | i | ) | const [inline] |
index grafalgo::List::next | ( | index | i | ) | const [inline] |
bool grafalgo::List::removeFirst | ( | ) | [inline] |
bool grafalgo::List::removeNext | ( | index | i | ) | [virtual] |
Remove the index following a specified index.
i | is index whose successor is to be removed; if zero, the first index is removed |
Reimplemented in grafalgo::Dlist.
Definition at line 121 of file List.cpp.
void grafalgo::List::resize | ( | int | size | ) | [virtual] |
Resize a List object.
The old value is discarded.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Reimplemented in grafalgo::Dlist.
Definition at line 56 of file List.cpp.
string & grafalgo::List::toString | ( | string & | s | ) | const [virtual] |
Create a string representation of a given string.
s | is string used to return value |
Implements grafalgo::Adt.
Definition at line 181 of file List.cpp.
bool grafalgo::List::valid | ( | index | i | ) | const [inline] |