Version: Next
链表工具类
节点
class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
}
}
打印链表
public class LinkedListUtils {
/**
* 打印函数
*
* @param node 头结点
*/
public static void print(ListNode node) {
StringBuilder stringBuilder = new StringBuilder();
while (node != null) {
stringBuilder.append(node.val).append(" -> ");
node = node.next;
}
stringBuilder.append("null");
System.out.println(stringBuilder.toString());
}
}