コード例 #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);
        }
コード例 #2
0
        public void InsertFirst(int id, decimal value)
        {
            DotnetLinkedList newLink = new DotnetLinkedList(id, value);

            newLink.next = first;
            first        = newLink;
        }
コード例 #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);
        }
コード例 #4
0
 public void DeleteFirst()
 {
     first = first.next;
 }