Tuesday, July 24, 2012

PIE LinkedList Methds

public Class Node{
   public Node next;
   public int data;

public Node(int d){
this.data = d;
this.next = null;
}

public Class LinkedLists{
   public Node head;

   public LinkedLists(){ //constructor
     this.next = null;
    this.data = null;
}
  public Node AddToFront(int obj){
   Node newNode = new Node(obj);
   newNode.next = head;
   return newNode; //return new head
}

public Node Find(int data){
   Node next = head;
   while (next!=null && next.data !=data){
      next = next.next;
  }
  return next;
}

}

No comments:

Post a Comment