Java中链表的创建

class ListNode{
    String val;        
    ListNode next = null;
    ListNode(String x)
    {
        val = x;
    }
}


public class lianbiao {
    public static void main(String[] args) {
        ListNode head = new ListNode("1");
        ListNode node1 = new ListNode("3");
        ListNode node2 = new ListNode("5");
        head.next = node1;
        node1.next = node2;
        while (head!=null){
            System.out.print(head.val + " ");
            head = head.next;
        }
    }
}

你可能感兴趣的:(链表,java,数据结构)