43 lines
747 B
Java
43 lines
747 B
Java
public class List {
|
|
private Node head;
|
|
private Node tail;
|
|
private int size;
|
|
|
|
public List(){
|
|
head = tail = null;
|
|
size = 0;
|
|
}
|
|
|
|
public boolean isEmply(){
|
|
return head == null;
|
|
}
|
|
|
|
public void append(Object data){
|
|
if(head == null){
|
|
head = tail = new Node(data);
|
|
size++;
|
|
return;
|
|
}
|
|
|
|
tail.next = new Node(data);
|
|
tail = tail.next;
|
|
size++;
|
|
}
|
|
|
|
public Object getItemAt(int index){
|
|
Node tmp = head;
|
|
int tmpIndex = 0;
|
|
while(tmpIndex < index){
|
|
tmp = tmp.next;
|
|
tmpIndex++;
|
|
}
|
|
return tmp.data;
|
|
}
|
|
|
|
public int getSize(){
|
|
return size;
|
|
}
|
|
|
|
|
|
}
|