日期:2014-05-17  浏览次数:21008 次

C#链表问题,新手求教
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace xxx
{
  interface ILinarList<T>
  {
  void InsertNode_End(T a);
  void InsertNode(T a, int x);
  int GetLength();
  }
  class SLinkList<T> : ILinarList<T>
  {
  private SNode<T> start;
  private int length;
  public SLinkList()
  {
  start = null;
  length = 0;
  }
  public void InsertNode_End(T a)
  {
  SNode<T> current;
  if (start == null)
  {
  start = new SNode<T>(a);
  length++;
  return;
  }
  current = start;
  while (current.Next != null)
  {
  current = current.Next;
  }
  current.Next = new SNode<T>(a);
  length++;
  }
  public void InsertNode(T a, int x)
  {
  SNode<T> current;
  SNode<T> previous = null ;
  SNode<T> newNode = new SNode<T>(a);
  if (x == 1)
  {
  newNode.Next = start;
  start.Next = newNode;
  length++;
  return;
  }
  int i = 1;
  current = start;
  while (i != x)
  {
  previous = current;
  current = current.Next;
  }
  previous.Next = newNode;
  newNode.Next = current;
  length++;
  }
  public int GetLength()
  {
  return length;
  }
  }
  class SNode<T>
  {
  private T data;
  private SNode<T> next;
  public SNode(T a)
  {
  data = a;
  next = null;
  }
  public T Data
  {
  get
  {
  return data;
  }
  set
  {
  data = value;
  }
  }
  public SNode<T> Next
  {
  get
  {
  return next;
  }
  set
  {
  next = value;
  }
  }
  }
  class Stu_Node
  {
  private string stu_ID;
  private string stu_Name;
  private int stu_Score;
  public Stu_Node(string stu_ID, string stu_Name, int stu_Score)
  {
  this.stu_ID = stu_ID;
  this.stu_Name = stu_Name;
  this.stu_Score = stu_Score;
  }
  public override string ToString()
  {
  return stu_ID + stu_Name;
  }
  }
  class Program
  {
  static void Main(st