home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
WDESAMPL.BIN
/
LinkList.java
< prev
next >
Wrap
Text File
|
1997-08-23
|
944b
|
59 lines
/**
* A simple one-directional external linked list class.
*/
public class LinkList extends Object
{
private LinkList therest;
private Object thevalue;
public LinkList(Object obj)
{
therest = null;
thevalue = obj;
}
/**
* Create a new list node; insert it at the head of the list. Return the list.
*/
public LinkList cons(Object obj)
{
LinkList newnode = new LinkList(obj);
newnode.thevalue = thevalue;
newnode.therest = therest;
therest = newnode;
thevalue = obj;
return this;
}
/**
* The object owned by the list node
*/
public Object value()
{
return thevalue;
}
/**
* The remainder of the list
*/
public LinkList rest()
{
return therest;
}
/**
* Swap the values of a and b.
*/
public static void swapValues(LinkList a, LinkList b)
{
Object save = a.thevalue;
a.thevalue = b.thevalue;
b.thevalue = save;
}
}