Java Applets Centre
Linked List


Description
This applet demonstrates the basic operations on a linked list data structure. A linked stack, and a linked queue are special cases of this linked list.


Code (A list node)

public class Node{
  int data;
  Node next;
}


Code (List operations)

public void insertEnd(int val){
  Node n = new Node();
  if(first==null) first=n;
  else last.next=n;
  n.data=val;
  last=n;
}
public void insertBegin(int val){
  Node n = new Node();
  n.next=first;
  if(first==null)last=n;
  first=n;
  n.data=val;
}
public void deleteBegin(){
  if(first==null)return;
  first=first.next;
}
public boolean isEmpty(){
  return (first==null)? true: false;
}


Data Structures and Algorithms
Java Applets Centre


R. Mukundan
Department of Computer Science
University of Canterbury
Private Bag 4800, Christchurch
New Zealand.