链表方法中的错误 [英] Errors in linked list methods
本文介绍了链表方法中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中的代码有问题.如果单击编译器"按钮,则会出现以下错误
I have a problem with my code in C# . if i click in compiler button , I get the following errors
The best overloaded method match for System.Collections.Generic.LinkedList<int?>.AddFirst(int?)'' has some invalid arguments, System.Collections.Generic.LinkedList<int?>'' does not contain a definition for Element and no extension method Element accepting a first argument of type System.Collections.Generic.LinkedList<int? could be found (are you missing a using directive or an assembly reference?) and Argument 1 cannot convert from void to int?
这是我程序的一部分
This is apart of my program
using System.;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Hanoi_tower
{
public class Sol
{
public LinkedList<int?> tower1 = new LinkedList<int?>();
public LinkedList<int?> tower2 =new LinkedList<int?>();
public LinkedList<int?> tower3 =new LinkedList<int?>();
public int depth;
public LinkedList<Sol> neighbors;
public Sol(LinkedList<int?> tower1, LinkedList<int?> tower2, LinkedList<int?> tower3)
{
this.tower1 = tower1;
this.tower2 = tower2;
this.tower3 = tower3;
neighbors = new LinkedList<Sol>();
}
public virtual void getneighbors()
{
Sol temp = this.copy();
Sol neighbor1 = this.copy();
Sol neighbor2 = this.copy();
Sol neighbor3 = this.copy();
Sol neighbor4 = this.copy();
Sol neighbor5 = this.copy();
Sol neighbor6 = this.copy();
if (temp.tower1.Count != 0)
{
if (neighbor1.tower2.Count != 0)
{
if (neighbor1.tower1.First.Value < neighbor1.tower2.First.Value)
{
neighbor1.tower2.AddFirst(neighbor1.tower1.RemoveFirst);
neighbors.AddLast(neighbor1);
}
}
else
{
neighbor1.tower2.AddFirst(neighbor1.tower1.RemoveFirst());
neighbors.AddLast(neighbor1);
}
if (neighbor2.tower3.Count != 0)
{
if (neighbor2.tower1.First.Value < neighbor2.tower3.First.Value)
{
neighbor2.tower3.AddFirst(neighbor2.tower1.RemoveFirst());
neighbors.AddLast(neighbor2);
}
}
else
{
neighbor2.tower3.AddFirst(neighbor2.tower1.RemoveFirst());
neighbors.AddLast(neighbor2);
}
}
//-------------
if (temp.tower2.Count != 0)
{
if (neighbor3.tower1.Count != 0)
{
if (neighbor3.tower2.First.Value < neighbor3.tower1.First.Value)
{
neighbor3.tower1.AddFirst(neighbor3.tower2.RemoveFirst());
neighbors.AddLast(neighbor3);
}
}
else
{
neighbor3.tower1.AddFirst(neighbor3.tower2.RemoveFirst());
neighbors.AddLast(neighbor3);
}
if (neighbor4.tower3.Count != 0)
{
if (neighbor4.tower2.First.Value < neighbor4.tower3.First.Value)
{
neighbor4.tower3.AddFirst(neighbor4.tower2.RemoveFirst());
neighbors.AddLast(neighbor4);
}
}
else
{
neighbor4.tower3.AddFirst(neighbor4.tower2.RemoveFirst());
neighbors.AddLast(neighbor4);
}
}
我真的不知道哪里出了问题.请帮忙,
I really dont know where it went wrong. Please help,
推荐答案
这是因为您没有为AddFirst方法提供正确的参数类型. AddFirst方法是否期望为int?作为一个论点.您正在提供RemoveFirst方法作为参数,其返回类型为void而不是int?.
That is because you are not providing correct argument type to the AddFirst method. AddFirst method is expecting a int? as an argument. You are providing RemoveFirst method as an argument which has a return type of void and not int?.
这篇关于链表方法中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文