2014-03-05 回答
package com.list; public class node<t extends number> { 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 <t extends number> { private node<t> head; private node<t> tail; private node<t> current; public void createlist(t[] data){ //list<t> list = new list<t>(); for (int i = 0; i < data.length; i++){ node<t> temp = new node<t>(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<t> gethead() { return head; } public void sethead(node<t> head) { this.head = head; } public node<t> gettail() { return tail; } public void settail(node<t> 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.length; i++){ data[i] = i + 10; } list<integer> temp = new list<integer>(); temp.createlist(data); temp.print(); } }