Esempio n. 1
0
        // Insert in sorted order.
        // x is the item to insert.
        public void Insert(AnyType x)
        {
            LinkedListIterator <AnyType> prev = Zeroth( );
            LinkedListIterator <AnyType> curr = First( );

            while (curr.IsValid( ) && x.CompareTo(curr.Retrieve( )) > 0)
            {
                prev.Advance( );
                curr.Advance( );
            }

            base.Insert(x, prev);
        }
    // Simple print method
    public static void PrintList <AnyType>(LinkedList <AnyType> theList)
    {
        if (theList.IsEmpty( ))
        {
            Console.WriteLine("Empty list");
        }
        else
        {
            LinkedListIterator <AnyType> itr = theList.First( );

            for ( ; itr.IsValid( ); itr.Advance( ))
            {
                Console.Write(itr.Retrieve( ) + " ");
            }
        }

        Console.WriteLine( );
    }