谁能把双向链表插入写成成C#程序(我写的不知道对不对)
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Doublelist
{
class TNode
{
public Object obj;
public TNode next, prev;
public TNode(Object obj, TNode next, TNode prev)
{
this.obj = obj;
this.next = next;
this.prev = prev;
}
}
class TList
{
private TNode first, last;
public TList(TNode first,TNode last)
{
this.first = first;
this.last = last;
}
public bool IsNull()//判断表是否为空
{
if (first == null)
return true;
return false;
}
public bool IsBof(TNode p)//判断是否插在表头
{
TNode NewTNode = new TNode(p.obj, p.next, p.prev);
if (NewTNode.next == first)
return true;
return false;
}
public bool IsLast(TNode p)//判断是否插在表尾
{
TNode NewTNode = new TNode(p.obj, p.next, p.prev);
if (NewTNode.prev == last)
return true;
return false;
}
private void Insert(object obj,TNode p)
{
TNode NewTNode = new TNode(p.obj,p.next,p.prev);
if (IsNull())
{
first = NewTNode;
last = NewTNode;
}
else
{
NewTNode.prev = p.prev;
p.prev.next = NewTNode;
p.prev = NewTNode;
NewTNode.next = p;
}
if (IsBof(p))
{
NewTNode.next = p;
p.prev = NewTNode;
NewTNode.prev = first;
}
if (IsLast(p))
{
NewTNode.prev = p;
p.next = NewTNode;
NewTNode.next = last;
}
}
public static void Main(string[] args)
{
}
}
}