//链表1
public class Node
{ public int Data;
public Node Next;
public Node()
{
Data=default(int);
Next=null;
}
public Node(int value)
{
Data=value;
Next=null;
}
}
//链表2
public class LinkList
{
private Node _head;
private int _count;
public LinkList()
{
_head=new Node();
_count=0;
}
//添加
public void AddItem(Node newNode)
{
Node Db=_head;
while(Db.Next!=null)
{
Db=Db.Next;
}
Db.Next=newNode;
_count++;
}
//获取长度
public int Getlength()
{
return _count;
}
//插入
public void Insert(int index,Node newNode)
{
if(index<=||index>_count)
{
console,writeline("搓比");
return;
}
Node Ls=_head;
for(int i=0;i<index;i++)
{
Ls=Ls.next;
}
newnode.next=ls.next;
ls.next=newnode;
_count++;
}
//删除
public Node RemoveAt(int index)
{
Node returnvalue=default(Node);
{
if(index<0||index>_count)
{
console.writeline("are you sb?");
return returnvalue;
}
Node mm=_head;
for(int i=0;i<index;i++)
{
mm=mm.next;
}
Node xmm=mm.next;
mm.next=mm.next.next;
mm.next.next=null;
_count--;
return xmm;
}
//遍历
public void ShowItem(Action<int,int> md)
{
if(_count==0)
{
console.writeline("你确定能行?");
return;
}
Node mm=_head/next;
for(int i=0;i<_count;i++)
{
md(i,mm.Data);
}
mm=mm.next;
}
//链表倒序
public void Dx()
{
Node node =_head;
Node up=null;
Node down;
node =node.next;
while(node!=null)
{
down=node.next;
node.next=up;
up=node;
node=down;
}
_head.next=up;
}
}
}