【发布时间】:2018-01-22 04:13:10
【问题描述】:
我试图在链接列表的末尾创建一个新节点,但不知何故它不起作用。请帮忙!
class Node{
int info;
Node next;
}
Node head;
void insert(int val){
Node nn = new Node();
nn.info = val;
Node cur = head;
if(cur==null){
cur = nn;
}
else{
while(cur.next!=null){
cur = cur.next;
}
cur.next = nn;
}
}
【问题讨论】:
-
只是为了您的信息,您应该接受并赞成正确答案并赞成其他有用的答案。这需要每个人的社区。阅读此 meta.stackexchange.com/a/5235
标签: java linked-list nodes