读取链表数据
using System;
public class ListNode
{
public int val;
public ListNode next;
public ListNode(int val = 0, ListNode next = null)
{
this.val = val;
this.next = next;
}
}
class Program
{
static void Main()
{
// 创建一个链表
ListNode head = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4))));
// 遍历并读取链表的数据
Console.WriteLine("链表的数据:");
ListNode current = head;
while (current != null)
{
Console.WriteLine(current.val);
current = current.next;
}
}
}
标签:链表,常用,ListNode,val,next,current,循环,new
From: https://www.cnblogs.com/sanzhixiaozhu/p/17880330.html