FileDocCategorySizeDatePackage
LinkList.javaAPI DocExample1415Sat Nov 25 12:56:22 GMT 2000None

LinkList

public class LinkList extends Object
Linked list class, written out in full using Java.
deprecated
Supplanted by java.util.LinkedList
author
Ian Darwin, ian@darwinsys.com

Fields Summary
protected TNode
root
protected TNode
last
Constructors Summary
LinkList()
Construct a LinkList: initialize the root and last nodes

		root = new TNode(this);
		last = root;
	
Methods Summary
voidadd(java.lang.Object o)
Add one object to the end of the list. Update the "next" reference in the previous end, to refer to the new node. Update "last" to refer to the new node.

		last.next = new TNode(o);
		last = last.next;
	
public booleanlookup(java.lang.Object o)

		for (TNode p=root.next; p != null; p = p.next)
			if (p.data==o || p.data.equals(o))
				return true;
		return false;
	
public static voidmain(java.lang.String[] argv)

		System.out.println("Here is a demo of writing a Linked List in Java");
		LinkList l = new LinkList();
		l.add(new Object());
		l.add("Hello");
		System.out.println("Here is a list of all the elements");
		l.print();
		if (l.lookup("Hello"))
			System.err.println("Lookup works");
		else
			System.err.println("Lookup does not work");
	
voidprint()

		for (TNode p=root.next; p != null; p = p.next)
			System.out.println("TNode" + p + " = " + p.data);