Exemplo n.º 1
0
 /// <summary> Insert after p.</summary>
 /// <param name="x">the item to insert.
 /// </param>
 /// <param name="p">the position prior to the newly inserted item.
 /// </param>
 public virtual void  insert(System.Object x, LinkedListItr p)
 {
     if (p != null && p.current != null)
     {
         p.current.next = new ListNode(x, p.current.next);
     }
 }
Exemplo n.º 2
0
        /// <summary> Remove the first occurrence of an item.</summary>
        /// <param name="x">the item to remove.
        /// </param>
        public virtual void  remove(System.Object x)
        {
            LinkedListItr p = findPrevious(x);

            if (p.current.next != null)
            {
                p.current.next = p.current.next.next;                 // Bypass deleted node
            }
        }
        /// <summary> Insert into the hash table. If the item is
        /// already present, then do nothing.
        /// </summary>
        /// <param name="x">the item to insert.
        /// </param>
        public virtual void  insert(Hashable x)
        {
            LinkedList    whichList = theLists[x.hash(theLists.Length)];
            LinkedListItr itr       = whichList.find(x);

            if (itr.PastEnd)
            {
                whichList.insert(x, whichList.zeroth());
            }
        }
Exemplo n.º 4
0
        // Simple print method
        public static void  printList(LinkedList theList)
        {
            if (theList.Empty)
            {
                System.Console.Out.Write("Empty list");
            }
            else
            {
                LinkedListItr itr = theList.first();
                for (; !itr.PastEnd; itr.advance())
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    System.Console.Out.Write(itr.retrieve() + " ");
                }
            }

            System.Console.Out.WriteLine();
        }