LeetCode 链表类、输出链表

文章目录

说明

这里给出的两个类是在刷力扣时的链表辅助类:

  1. ListNode 链表节点类
  2. ListNodeMgr 链表管理类(输出链表元素)

代码

ListNode

public class ListNode
{
    
    
    public int val;
    public ListNode next;
    public ListNode(int val = 0, ListNode next = null)
    {
    
    
        this.val = val;
        this.next = next;
    }
}

ListNodeMgr

public class ListNodeMgr
{
    
    
    public static void PrintListNode(ListNode head)
    {
    
    
        ListNode tempNode = head;
        while(tempNode != null)
        {
    
    
            Debug.Log(tempNode.val);
            tempNode = tempNode.next;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_45136016/article/details/131478643