时间:2021-05-20
复制代码 代码如下:
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.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;
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
C语言数据结构之循环链表的简单实例实例代码:#include#includetypedefstructnode//定义链表中结点的结构{intcode;stru
数据结构C语言实现循环单链表的实例实例代码://=========杨鑫========================////循环单链表的实现#include#
数据结构之双向循环链表实例代码:#include#include#includetypedefstructNode{structNode*pNext;intda
C/C++双链表之逆序的实例详解一、结点结构双向链表的数据结构定义如下:typedefstructnode{ElemTypedata;structnode*pr
C语言数据结构之使用链表模拟栈的实例以下是“使用链表模拟栈”的简单示例:1.用C语言实现的版本#include#includetypedefchardataty