package BoxTools;
/**
* A List
object maintains a linked list of elements of type T
.
* Each element is contained in a Link
object, and these Link
* objects are linked together. A List
object has a pointer to these linked
* Link
objects, which are linked in one way.
* A List
object must be declared local, but the elements in it can be global.
* List
is implemented like a stack. The first element added to it appears at
* the end of the list.
*
Usage: A List
object must be declared local.
* @see Link
* @version 1.1
* @author Tong Wen, LBNL
* @since 1.0
*/
templateLink
object, which contains the last element. */
protected template LinkLink
object in the list. */
protected template Linkcurruentlink==null
, using this method will cause a runtime exception. */
public final inline local void setElement(T element){currentLink.element=element;}
public final inline local boolean endp(){return (currentLink==null);}
public final inline local void reset(){currentLink=firstLink;}
/** Returns the element at position index
.
* If index
is out of range, the last element is returned.
*/
public final local T elementAt(int index){
if (index>=size) {
Util.printErrMsg("List::elementAt( ): the index is out of range! The last element will be returned.");
index=size;
}
int steps=size-index-1;
reset();
for (int i=0;iindex
is out of range, the last element is set.
*/
public final local void setElementAt(T newElement, int index){
if (index>=size) {
Util.printErrMsg("List::elementAt( ): the index is out of range!");
return;
}
else{
int steps=size-index-1;
reset();
for (int i=0;i