Esempio n. 1
0
        public Link Delete(int key)
        {
            Link current = first;
            Link previous = first;

            while (current.Data != key)
            {
                if (current.Next == null)
                {
                    return null;
                }
                previous = current;
                current = current.Next;
            }

            if (current == first)
            {
                first = first.Next;
            }
            else
            {
                previous.Next = current.Next;
            }

            return current;
        }
Esempio n. 2
0
        public Link DeleteFirst()
        {
            Link temp = first;
            first = first.Next;

            return temp;
        }
Esempio n. 3
0
 public void InsertFirst(int data)
 {
     var newLink = new Link {Data = data, Next = first};
     first = newLink;
 }
Esempio n. 4
0
 public LinkedList()
 {
     first = null;
 }