user3335037
user3335037

Reputation: 3

C# : Return Last node of linked list

tryin to implement stack with linked list, have trouble in pop, the code

 public class MyItemType
    {
    ................
    }

 class MyStack
    {

        LinkedList<MyItemType> ourList = null;
        MyItemType top = null;

................

 public MyItemType Pop()
            {
                if (IsEmpty())
                {
                  return null;
                }
                else
                {
                    MyItemType temp = ourList.Last;  // <--- issue here
                    ourList.RemoveLast();
                    return temp;
                }
            }


................

}

error: Error 2 Cannot implicitly convert type 'System.Collections.Generic.LinkedListNode' to 'Ex1.MyItemType'

Upvotes: 0

Views: 608

Answers (1)

pollirrata
pollirrata

Reputation: 5286

You need to do like this

ourList.Last.Value

documentation

Upvotes: 3

Related Questions