java链表代码实现 java链表怎么实现( 五 )


}
temp.setNext(node2);
printList(head);
}
//构建链表
public static Node buildList(String[] numStr) {
if(0 == numStr.length) {
return null;
}
Node head = new Node();
head.setData(Integer.parseInt(numStr[0]));
head.setNext(null);
Node temp = head;
for(int i = 1; inumStr.length; i++) {
Node node = new Node();
node.setData(Integer.parseInt(numStr[i]));
node.setNext(null);
temp.setNext(node);
temp = node;
}
return head;
}
//输出链表
public static void printList(Node head) {
Node temp = head;
while(temp != null) {
System.out.print(temp.getData() + "--");
temp = temp.getNext();
}
System.out.println();
}
public int getData() {
return data;
}
public void setData(int data) {
this.data = https://www.04ip.com/post/data;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}
java链表代码实现的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java链表怎么实现、java链表代码实现的信息别忘了在本站进行查找喔 。