Ejemplo n.º 1
0
        // assumes a non empty list:
        public DotnetLinkedList Delete(int key)
        {
            DotnetLinkedList currentLink  = first;
            DotnetLinkedList previousLink = first;

            while (currentLink.key != key)
            {
                if (currentLink.next == null)
                {
                    return(null);
                }
                previousLink = currentLink;
                currentLink  = currentLink.next;
            }
            if (currentLink == first)
            {
                first = first.next;
            }
            else
            {
                //currentLink which is the node to be deleted will be bypass
                previousLink.next = currentLink.next;
            }
            return(currentLink);
        }
Ejemplo n.º 2
0
        public void InsertFirst(int id, decimal value)
        {
            DotnetLinkedList newLink = new DotnetLinkedList(id, value);

            newLink.next = first;
            first        = newLink;
        }
Ejemplo n.º 3
0
        public DotnetLinkedList FindLinear(int key)
        {
            DotnetLinkedList currentLink = first; //start at the first link item

            while (currentLink.key != key)
            {
                if (currentLink.next == null)
                {
                    return(null);
                }
                currentLink = currentLink.next;
            }
            return(currentLink);
        }
Ejemplo n.º 4
0
 public void DeleteFirst()
 {
     first = first.next;
 }