/* Written by Jen Chen Updated on March the 4th, 2003 Copyrighted by Jen Chen */ package linklist; import java.util.*; public class LinkListDriver { static IntNode head = null;//global variable. public static void main(String[] args) { head = new IntNode(3, head);//Initialize the first node with data = "3". This is the head node. IntNode node2 = null; head.addNodeAfter(22); head.addNodeAfter(21); System.out.println("The length of the link list is: " + head.listLength(head)); System.out.println("Data of the \"head\" node is: " + head.getData()); System.out.println("Data at the current node of the \"head\" node is: " + head.listAdvance(head).getData()); System.out.println("Data at the current node of the \"head\" node is: " + head.listAdvance(head.listAdvance(head)).getData()); node2 = head;//Set node2 top be the "head" node. System.out.println("Data at the current node of node2 is: " + node2.getData()); node2 = node2.listAdvance(node2);//move to the next node. System.out.println("Data at the current node of node2 is: " + node2.getData()); node2.addNodeAfter(23); node2.addNodeAfter(24); node2.addNodeAfter(28); node2.addNodeAfter(31); node2 = node2.listAdvance(node2); node2 = node2.listAdvance(node2); node2 = node2.listAdvance(node2); System.out.println("Data at the current node of node2 is: " + node2.getData()); System.out.println("The length of the node \"head\" list is: " + head.listLength(head)); System.out.println("data of the head node is: " + head.getData()); System.out.println("Here is the list of data from the node \"head\":"); showAll(head); System.out.println("\nThe data of the node BEFORE node 5 is: " + previousData(5)); System.out.println("The first data found for 24 is at position of the node head: " + head.firstFoundData(head,24)); // int[] node = null; // node = node2.nodePosition(head, 23); Vector vtr = node2.nodePosition(head,23); for(int j = 0; j < vtr.size(); j++) System.out.println("The position of 23 occurs at node: " + vtr.elementAt(j)); System.out.println("Here is the data from the current node:"); System.out.print(node2.getData()); node2.removeNodeAfter(); System.out.println("\nAfter removing the node after the current node, here is the data from the list:"); showAll(head); }//end of main() ///////////////////////////////////////////////////////////////////// public static int previousData(int position){//Method added by JC int pos = 0; IntNode tmp = null; tmp = tmp.listPosition(head,(position - 1)); return tmp.getData(); }//end of method previousNode() public static void showAll(IntNode nod){//method added by JC IntNode tmp = head; for(int i = 0; i < tmp.listLength(nod); i++){ if(i%10 != 9){ System.out.print(tmp.getData() + "\t"); tmp = tmp.listAdvance(tmp); } else{ System.out.print(tmp.getData() + "\n"); tmp = tmp.listAdvance(tmp); } }//end of FOR() }//end of showAll() ///////////////////////////////////////////////////////////////////// }//end of class LinkListDriver{}