removeFirst and addLast methods of LinkedList Class are Unknown
        Posted  
        
            by user318068
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user318068
        
        
        
        Published on 2010-06-02T19:10:40Z
        Indexed on 
            2010/06/02
            19:54 UTC
        
        
        Read the original article
        Hit count: 486
        
I have a problem with my code in C# . if i click in compiler button , I get the following errors
'
System.Collections.Generic.LinkedList<int?>' does not contain a definition for 'removeFirst' and no extension method 'removeFirst' 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
'
System.Collections.Generic.LinkedList<Hanoi_tower.Sol>' does not contain a definition for 'addLast' and no extension method 'addLast' accepting a first argument of type 'System.Collections.Generic.LinkedList<Hanoi_tower.Sol>' could be found (are you missing a using directive or an assembly reference?)
This is 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);
            }
        }
        //------------------------
        if (temp.tower3.Count() != 0)
        {
            if (neighbor5.tower1.Count() != 0)
             {
                if(neighbor5.tower3.ElementAtOrDefault() < neighbor5.tower1.ElementAtOrDefault())
                {
                    neighbor5.tower1.AddFirst(neighbor5.tower3.RemoveFirst());
                neighbors.AddLast(neighbor5);
                }
             }
                 else
                 {
             neighbor5.tower1.AddFirst(neighbor5.tower3.RemoveFirst());
             neighbors.AddLast(neighbor5);
                 }
            if (neighbor6.tower2.Count() != 0)
             {
                if(neighbor6.tower3.element() < neighbor6.tower2.element())
                {
                    neighbor6.tower2.addFirst(neighbor6.tower3.removeFirst());
                 neighbors.addLast(neighbor6);
            }
             }
                else
                {
             neighbor6.tower2.addFirst(neighbor6.tower3.removeFirst());
             neighbors.addLast(neighbor6);
                }
            }
    }
        public override string ToString()
{
    string str;
    str="tower1"+ tower1.ToString() + "   tower2" + tower2.ToString() + "   tower3" + tower3.ToString();
    return str;
}
        public Sol copy()
{
    Sol So;
     LinkedList<int> l1= new LinkedList<int>();
     LinkedList<int> l2=new LinkedList<int>();
     LinkedList<int> l3 = new LinkedList<int>();
     for(int i=0;i<=this.tower1.Count() -1;i++)
     {
         l1.AddLast(tower1.get(i));
     }
      for(int i=0;i<=this.tower2.size()-1;i++)
     {
         l2.addLast(tower2.get(i));
     }
      for(int i=0;i<=this.tower3.size()-1;i++)
     {
         l3.addLast(tower3.get(i));
     }
      So = new Sol(l1, l2, l3);
     return So;
}
        public bool Equals(Sol sol)
{
    if (this.tower1.Equals(sol.tower1) & this.tower2.Equals(sol.tower2) & this.tower3.Equals(sol.tower3))
        return true;
    return false;
}
        public virtual bool containedin(Stack<Sol> vec)
     {
         bool found =false;
         for(int i=0;i<= vec.Count-1;i++)
         {
            if(vec.get(i).tower1.Equals(this.tower1) && vec.get(i).tower2.Equals(this.tower2) && vec.get(i).tower3.Equals(this.tower3))
            {
                found=true;
              break;
         }
         }
         return found;
     }
}
    }
© Stack Overflow or respective owner