I saw a single-chain table mentioned in the title of a post and suddenly remembered that I had never written the code for a single-chain table. I figured out the simplest one, generic is used to improve applicability.
Java code
Package com. iteye. bolide74.test;
Public class SingleLinkedList {
Public static void main (String [] args ){
List <Integer> list = new List <Integer> ();
List. add (1 );
List. add (2 );
List. add (3 );
List. add (4 );
List. add (5 );
Note <Integer> head = list. head;
While (head. hasNext ()){
System. out. println (head. value );
Head = head. next;
}
}
}
Class Note <E> {
Public E value;
Public Note <E> next;
Public Note (E val, Note <E> next ){
This. value = val;
This. next = next;
}
Public boolean hasNext (){
Return this. next! = Null;
}
}
Class List <E> {
Public Note <E> head;
Public List (){
This. head = new Note <E> (null, null );
}
Public void add (E val ){
This. head = new Note <E> (val, this. head );
}
}
Author: "Eight claw is me"