C# 链表结构(1)-结点
以一个类来定义结点类,其中包含结点数据值,前结点,后结点(双向链表的情况有前、后结点)。
using System;
using System.Collections.Generic;
using System.Text;
namespace Csharp
{
public class Node<T> where T : IComparable<T>
{
T data;
/// <summary>
/// the current data
/// </summary>
public T Data
{
get
{
return this.data;
}
set
{
this.data = value;
}
}
Node<T> next;
/// <summary>
/// the next node
/// </summary>
public Node<T> Next
{
get
{
return this.next;
}
set
{
this.next = value;
}
}
Node<T> prev;
/// <summary>
/// the prev node
/// </summary>
public Node<T> Prev
{
get
{
return this.prev;
}
set
{
this.prev = value;
}
}
/// <summary>
/// no arguments to constitution
/// </summary>
public Node()
{
this.data = default(T);
this.next = null;
this.prev = null;
}
/// <summary>
/// one data to constitution
/// </summary>
/// <param name="t">a data</param>
public Node(T t)
{
this.data = t;
this.next = null;
this.prev = null;
}
/// <summary>
/// three data to constitution
/// </summary>
/// <param name="t">the current data</param>
/// <param name="next_">the next data</param>
/// <param name="prev_">the previous data</param>
public Node(T t, Node<T> next_, Node<T> prev_)
{
this.data = t;
this.next = next_;
this.prev = prev_;
}
}
}
参考自:http://www.cnblogs.com/linzheng/news/2011/07/14/2106530.html
作者:Ivan
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步