home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-08-23 | 944 b | 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;
- }
- }
-
-