C#數(shù)據(jù)結(jié)構(gòu)之循環(huán)鏈表的實(shí)例代碼
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
{
//頭結(jié)點(diǎn)
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.WriteLine(current.Link.Element);
current = current.Link;
}
}
private Node FindPrevious(object n)
{
Node current = Header;
while (!(current.Link == null) && current.Link.Element != n)
{
current = current.Link;
}
return current;
}
private Node Find(object item)
{
Node current = new Node();
current = Header.Link;
while (current.Element != item)
{
current = current.Link;
}
return current;
}
public void Insert(object newItem, object after)
{
Node current = new Node();
Node newNode = new Node(newItem);
current = Find(after);
newNode.Link = current.Link;
current.Link = newNode;
count++;
}
public void Remove(object n)
{
Node p = FindPrevious(n);
if (!(p.Link == null))
{
p.Link = p.Link.Link;
count--;
}
}
public void InsertFirst(object n)
{
Node current = new Node(n);
current.Link = Header;
Header.Link = current;
count++;
}
public Node Move(int 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;
}
}
相關(guān)文章
C#判斷指定驅(qū)動(dòng)器是否已經(jīng)準(zhǔn)備就緒的方法
這篇文章主要介紹了C#判斷指定驅(qū)動(dòng)器是否已經(jīng)準(zhǔn)備就緒的方法,涉及C#針對(duì)硬件IO操作的技巧,需要的朋友可以參考下2015-04-04
C#實(shí)現(xiàn)設(shè)置Excel表格中文本對(duì)齊方式和格式
這篇文章主要為大家詳細(xì)介紹了如何在.NET 程序中通過C# 設(shè)置Excel單元格中文本的對(duì)齊方式,方向以及換行,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-04-04
解決WPF附加屬性的Set函數(shù)不調(diào)用的問題
這篇文章介紹了解決WPF附加屬性的Set函數(shù)不調(diào)用的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
Unity?UGUI的PhysicsRaycaster物理射線檢測(cè)組件介紹使用
這篇文章主要介紹了Unity?UGUI的PhysicsRaycaster物理射線檢測(cè)組件的介紹及使用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07

