网站首页 语言 会计 电脑 医学 资格证 职场 文艺体育 范文
当前位置:书香门第 > 计算机 > C语言

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

栏目: C语言 / 发布于: / 人气:2.77W

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

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

复制代码 代码如下:

public class Node

{

public object Element;

public Node Link;

public Node()

{

Element = null;

Link = null;

}

public Node(object theElement)

{

Element = theElement;

Link = null;

}

}

复制代码 代码如下:

public class LinkedList

{

//头结点

protected Node Header;

private int count;

public LinkedList()

{

count = 0;

Header = new Node("header");

= Header;

}

public bool IsEmpty()

{

return ( == null);

}

public void MakeEmpty()

{

= null;

}

public void PrintList()

{

Node current = new Node();

current = Header;

while (ring() != "header")

{

eLine(ent);

current = ;

}

}

private Node FindPrevious(object n)

{

Node current = Header;

while (!( == null) && ent != n)

{

current = ;

}

return current;

}

private Node Find(object item)

{

Node current = new Node();

current = ;

while (ent != item)

{

current = ;

}

return current;

}

public void Insert(object newItem, object after)

{

Node current = new Node();

Node newNode = new Node(newItem);

current = Find(after);

= ;

= newNode;

count++;

}

public void Remove(object n)

{

Node p = FindPrevious(n);

if (!( == null))

{

= ;

count--;

}

}

public void InsertFirst(object n)

{

Node current = new Node(n);

= Header;

= current;

count++;

}

public Node Move(int n)

{

Node current = ;

Node tmp;

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

{

current = ;

}

if (ring() == "header")

{

current = ;

}

tmp = current;

return tmp;

}

public Node GetFirst()

{

return Header;

}

}