我写的代码
可以啊
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication
{
class Node<T>
{
public T data;
public Node<T> next;
public Node()
{
this.data = default(T);
this.next = null;
}
public Node(T t)
{
this.data = t;
this.next = null;
}
}
}
--------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication
{
class LinkList<T>
{
private Node<T> hNode;
private Node<T> tmpNode;
public LinkList()
{
this.hNode = new Node<T>();
}
public void AddItem(T t)
{
this.tmpNode = this.hNode;
while (this.tmpNode.next != null)
{
this.tmpNode = this.tmpNode.next;
}
this.tmpNode.next = new Node<T>(t);
}
public void LinkItem()
{
this.tmpNode = this.hNode;
while (this.tmpNode.next != null)
{
this.tmpNode = this.tmpNode.next;
}
this.tmpNode.next = this.hNode.next;
}
public bool IsCycle()
{
Node<T> n1;
Node<T> n2;
n1 = hNode;
n2 = hNode;
do
{
n2 = n2.next;
n1 = n1.next.next;
if (n1 == null)
{
return false;
}
} while (!n1.Equals(n2));
return true;
}
public void Show()
{
Node<T> n;
n = hNode;
while (n.next != null)
{
Console.WriteLine(n.data);
n = n.next;
}
}
public T this[int index]
{
get
{
this.tmpNode = this.hNode;
while((index--)!=0)
{
this.tmpNode = this.tmpNode.next;
}
return this.tmpNode.data;
}
}
}
}