package com.list;
public class Node {
private Node next;
private T data;
public Node(){
this(null, null);
}
public Node(Node next, T data){
this.next = next;
this.data = data;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
@Override
public String toString() {
return "Node " + ", data=" + data;
}
}package com.list;
public class List {
private Node head;
private Node tail;
private Node current;
public void createList(T[] data){
//List list = new List();
for (int i = 0; i
Node temp = new Node(null, data[i]);
if (0 == i){
head = temp;
current = temp;
continue;
}
tail = temp;
current.setNext(temp);
current = temp;
}
//return list;
}
public List(){
head = null;
tail = null;
}
public Node getHead() {
return head;
}
public void setHead(Node head) {
this.head = head;
}
public Node getTail() {
return tail;
}
public void setTail(Node tail) {
this.tail = tail;
}
private void print(){
current = head;
while (current != null){
System.out.println(current.toString());
current = current.getNext();
}
}
public static void main(String[] args) {
Integer[] data = new Integer[5];
for (int i = 0; i
data[i] = i + 10;
}
List temp = new List();
temp.createList(data);
temp.print();
}
}
温馨提示:答案为网友推荐,仅供参考