假定初始curr_node始终为head。 LLNode的实现遵循此代码段的实现。我该如何运作?
private String toString(LLNode<Integer> curr_node) {
// TODO
if(curr_node==null)
{
return "";
}
else
{
return curr_node.data+toString(curr_node.link);
}
}
public class LLNode<T> {
public T data;
public LLNode<T> link;
public LLNode() {
this(null, null);
}
public LLNode(T data, LLNode<T> link) {
this.data = data;
this.link = link;
}
}
答案 0 :(得分:0)
请参阅:
private String toString(LLNode<Integer> curr_node) {
if(curr_node==null)
{
return "";
}
else
{
return toString(curr_node.link) + "," + curr_node.data; // Your code is the reverse
}
}