intermediate/LinkListImplementation

From ggc

Jump to: navigation, search

01 package intermediate;
02 //start auto-imports
03 import com.sun.org.apache.bcel.internal.generic.*;
04 //end auto-imports
05 
06 
07 /**
08  * All about my helper class.
09  @author Jam Jenkins
10  */
11 public class LinkListImplementation
12 {
13   private LinkedListNode head;
14   private LinkedListNode tail;
15 
16   public void addFirst(String data)
17   {
18     if(head==null)
19     {
20       LinkedListNode node=new LinkedListNode(data, nullnull);
21       head=node;
22       tail=node;
23     }
24     else
25     {
26       LinkedListNode node=new LinkedListNode(data, head, null);
27       head.prev=node;
28       head=node;
29     }
30   }
31 
32   public void addLast(String data)
33   {
34     if(head==null)
35     {
36       LinkedListNode node=new LinkedListNode(data, nullnull);
37       head=node;
38       tail=node;
39     }
40     else
41     {
42       LinkedListNode node=new LinkedListNode(data, null, tail);
43       tail.next=node;
44       tail=node;
45     }
46   }
47 
48   public String toString()
49   {
50     LinkedListNode current=head;
51     String total="head<->";
52     while(current!=null)
53     {
54       total+=current.data+"<->";
55       current=current.next;
56     }
57     total+="tail";
58     return total;
59   }
60 
61 }


Download/View intermediate/LinkListImplementation.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter