日期:2014-05-17 浏览次数:20795 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericSamp
{
public class Student
{
private string StudentName;
private int StudentAge;
public Student(string name, int age)
{
this.StudentName = name;
this.StudentAge = age;
}
public override string ToString()
{
return this.StudentName + ":年龄" + this.StudentAge + "岁";
}
}
public class Node<T>
{
T data;
Node<T> next;
public Node(T data)
{
this.data=data;
this.next=null;
}
public T Data{
get {return this.data;}
set{data=value;}
}
public Node<T> Next{
get{return this.next;}
set{this.next=value;}
}
public void Append(Node<T> newNode){
if(this.next==null){this.next=newNode;}
else{next.Append(newNode);}
}
public override string ToString(){
string output=data.ToString();
if(next!=null){output+=","+next.ToString();}
return output;
}
}
public class LinkedList<T>
{
Node<T> headNode = null;
public void Add(T data)
{
if (headNode == null)
{
headNode = new Node<T>(data);
}
else
{
&nb