好好学习,天天向上,好运知识库欢迎您!
当前位置:首页 >  考试 >  计算机类 > 内容页

C#数据结构之循环链表的实例代码

2021-01-27 13:10:01计算机类访问手机版495

  很多人都不知道C#数据结构中循环链表的代码怎么写,下面小编为大家整理了C#数据结构之循环链表的实例代码,希望能帮到大家!

  复制代码 代码如下:

  public class Node

  public object Element;

  public Node Link;

  public Node

  Element = null;

  Link = null;

  public Nodeobject theElement

  Element = theElement;

  Link = null;

  复制代码 代码如下:

  public class LinkedList

  //头结点

  protected Node Header;

  private int count;

  public LinkedList

  count = 0;

  Header = new Node"header";

  Header.Link = Header;

  public bool IsEmpty

  return Header.Link == null;

  public void MakeEmpty

  Header.Link = null;

  public void PrintList

  Node current = new Node;

  current = Header;

  while current.Link.Element.ToString != "header"

  Console.WriteLinecurrent.Link.Element;

  current = current.Link;

  private Node FindPreviousobject n

  Node current = Header;

  while !current.Link == null && current.Link.Element != n

  current = current.Link;

  return current;

  private Node Findobject item

  Node current = new Node;

  current = Header.Link;

  while current.Element != item

  current = current.Link;

  return current;

  public void Insertobject newItem, object after

  Node current = new Node;

  Node newNode = new NodenewItem;

  current = Findafter;

  newNode.Link = current.Link;

  current.Link = newNode;

  count++;

  public void Removeobject n

  Node p = FindPreviousn;

  if !p.Link == null

  p.Link = p.Link.Link;

  count--;

  public void InsertFirstobject n

  Node current = new Noden;

  current.Link = Header;

  Header.Link = current;

  count++;

  public Node Moveint n

  Node current = Header.Link;

  Node tmp;

  for int i = 0; i <= n; i++

  current = current.Link;

  if current.Element.ToString == "header"

  current = current.Link;

  tmp = current;

  return tmp;

  public Node GetFirst

  return Header;

TAG标签: 数据结构 之循 环链 实例 代码