我成功地从头开始创建了一个LinkedList.到目前为止,它只能添加数据.没有删除或任何类似的东西.
我可以添加字符串,整数等但我有打印我添加的数据的问题.我怎么做?我想我必须首先完成它,但是怎么样?
这是我的Node类:
public class Node {
T data;
Node<T> nextNode;
public Node(T data) {
this.data = data;
}
public String toString () {
return data +"";
}
}
Run Code Online (Sandbox Code Playgroud)
这是LinkedList类:
public class LinkedList <T> {
Node<T> head;
Node<T> tail;
public void add (T data) {
// where to add statements. if its empty or not
Node<T> node = new Node<T> (data);
if (tail == null) { // empty list
// nothng in the node = tail = node;
head = …Run Code Online (Sandbox Code Playgroud) java ×1