[补水]泛型实现的万能链表
using System;
using System.Collections.Generic;
using System.Text;
namespace TLists
{
class TList<T>
{
public TList()
{
this.head = null;
}
class Node
{
private Node next;
private T data;
public Node()
{ }
public Node(T data)
{
this.data = data;
this.next = null;
}
public T Data
{
get { return data; }
set { data = value; }
}
public Node Next
{
get { return next; }
set { next = value; }
}
}
public void Add(T data)
{
Node newNode = new Node(data);
newNode.Next = head;
head = newNode;
}
public void Show()
{
Node temp = this.head;
while (!(temp == null))
{
Console.Write(temp.Data.ToString() + "\t");
temp = temp.Next;
}
}
private Node head;
}
class MainClass
{
static void Main()
{
TList<int> list = new TList<int>();
Random random = new Random();
for (int i = 0; i < 5;i++ )
{
int r = random.Next() % 30;
list.Add(r);
}
list.Show();
Console.ReadLine();
}
}
}
<>里面是什么就能装什么,这就是泛型的作用 太爱国了~~
不懂是什么东西~~~ c语言呀~~~~~~~~多发些上来呀~~~ 你翻翻一大堆`````````
页:
[1]