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(string[] args)
{
ILinarList<SNode<Stu_Node>> stu_list = null;
char Y_N;
while (true)
{
int choice;
Console.WriteLine("有以下可执行的操作:");
Console.WriteLine("1.输入学生信息或在末尾加入学生信息");
Console.WriteLine("2.在第k个学生前插入学生信息");
Console.WriteLine("3.在指定学号或姓名的学生前插入学生信息");
Console.WriteLine("4.删除第k个学生的信息");
Console.WriteLine("5.删除指定学号或姓名的学生的信息");
Console.WriteLine("6.查看第k个学生的信息");
Console.WriteLine("7.查看指定学号或姓名的学生的信息");
Console.WriteLine("8.显示学生表信息");
Console.WriteLine("9.查看以注册信息的学生总人数");
Console.WriteLine("10.清空学生信息表");
Console.WriteLine("11.退出");
Console.Write("请选择:");
try
{
choice = Int32.Parse(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("Please enter an integer");
continue;
}
if (choice > 11 || choice < 1)
{
Console.WriteLine("Beyond the range of choice");
Console.Write("Press any key to continue...");
Console.Read();
continue;
}
else
{
switch (choice)
{
case 1:
while (true)
{
string stu_ID, stu_name;
int stu_score;
char ch;
Console.Write("请输入学生学号:");
stu_ID = Console.ReadLine();
Console.Write("请输入学生姓名:");
stu_name = Console.ReadLine();
Console.Write("请输入学生成绩:");
try
{
stu_score = Int32.Parse(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("score input errors");
continue;
}
if (stu_score < 0 || stu_score > 100)
{
Console.WriteLine("score overflow");
continue;
}
Stu_Node stu_Node = new Stu_Node(stu_ID, stu_name, stu_score);
stu_list.InsertNode_End(stu_Node);
Console.WriteLine("是否继续输入?(Y/N)");
ch = char.Parse(Console.ReadLine());
if (ch == 'n' || ch == 'N')
{
break;
}
}
break;
case 2:
while (true)
{
string stu_ID, stu_name;
int stu_score;
char ch;
int k;
Console.Write("请问在第多少个学生前插入数据?请输入:");
try
{
k = Int32.Parse(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("error,Please enter an integer");
continue;
}
if (k < 1 || k > stu_list.GetLength())
{
Console.WriteLine("the number must between 1 and {0}", stu_list.GetLength());
continue;
}
Console.Write("请输入学生学号:");
stu_ID = Console.ReadLine();
Console.Write("请输入学生姓名:");
stu_name = Console.ReadLine();
Console.Write("请输入学生成绩:");
try
{
stu_score = Int32.Parse(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("score input errors");
continue;
}
if (stu_score < 0 || stu_score > 100)
{
Console.WriteLine("score overflow");
continue;
}
Stu_Node stu_Node = new Stu_Node(stu_ID, stu_name, stu_score);
stu_list.InsertNode(stu_Node, k);
Console.WriteLine("是否继续插入?(Y/N)");
ch = char.Parse(Console.ReadLine());
if (ch == 'n' || ch == 'N')
{
break;
}
}
break;
}
Console.WriteLine("是否继续进行操作?(Y/N)");
Y_N = char.Parse(Console.ReadLine());
if (Y_N == 'n' || Y_N == 'N')
{
break;
}
}
}
}
}
}
红色子图部分为报错部分,两个地方的错误相同,错误提示如下,绿色字体可以直接忽略
-----------------------------------------------------------------------------------------------------------------------------------------
错误 1 与“xxx.ILinarList<xxx.SNode<xxx.Stu_Node>>.InsertNode_End(xxx.SNode<xxx.Stu_Node>)”最匹配的重载方法具有一些无效参数
错误 2 参数 1: 无法从“xxx.Stu_Node”转换为“xxx.SNode<xxx.Stu_Node>”
-----------------------------------------------------------------------------------------------------------------------------------------
求解...