Hello all,
This will be a bit of a long post due to the coding, my apologies.
This is a homework assignment, I am soooo close to finishing it.
I just have a couple of pesky bugs I am pulling my, what little I have left, hair.

We are using the Deitel Visual C# and the LinkedListLibrary and the StackInheritance
are used from the book. My part of the program that is using these 2 sources is my problem.

First off for using both the StackInheritance class and then the System.Collections.Stack
I am to see how low it takes for it to insert 10000, 100000, 1000000 and 10000000 random integers. Then record how long it takes to insert/push these number of items(emptying the stack after each run).

The Program.cs is the part I am needing help with and am sending the complete program in 3 sections.

// Fig. 25.4: LinkedListLibrary.cs
// Class ListNode and class List declarations.
using System;

namespace LinkedListLibrary
{
   // class to represent one node in a list
   class ListNode
   {
      private object data; // stores data for this node
      private ListNode next; // stores a reference to the next node

      // constructor to create ListNode that refers to dataValue
      // and is last node in list
      public ListNode( object dataValue ) 
         : this( dataValue, null )
      {
      } // end default constructor
      
      // constructor to create ListNode that refers to dataValue
      // and refers to next ListNode in List
      public ListNode( object dataValue, ListNode nextNode )
      {
         data = dataValue;  
         next = nextNode;    
      } // end constructor
      
      // property Next
      public ListNode Next
      {
         get
         {
            return next;
         } // end get
         set
         {
            next = value;
         } // end set
      } // end property Next

      // property Data
      public object Data
      {
         get
         {
            return data;
         } // end get
      } // end property Data
   } // end class ListNode

   // class List declaration
   public class List
   {
      private ListNode firstNode;
      private ListNode lastNode;
      private string name; // string like "list" to display

      // construct empty List with specified name
      public List( string listName )
      {
         name = listName;
         firstNode = lastNode = null;
      } // end constructor
      
      // construct empty List with "list" as its name
      public List() 
         : this( "list" )
      { 
      } // end default constructor
   
      // Insert object at front of List. If List is empty, 
      // firstNode and lastNode will refer to same object.
      // Otherwise, firstNode refers to new node.
      public void InsertAtFront( object insertItem )
      {
         if ( IsEmpty() )
            firstNode = lastNode = new ListNode( insertItem );
         else
            firstNode = new ListNode( insertItem, firstNode );
      } // end method InsertAtFront

      // Insert object at end of List. If List is empty, 
      // firstNode and lastNode will refer to same object.
      // Otherwise, lastNode's Next property refers to new node.
      public void InsertAtBack( object insertItem )
      {
         if ( IsEmpty() )
            firstNode = lastNode = new ListNode( insertItem );
         else
            lastNode = lastNode.Next = new ListNode( insertItem );
      } // end method InsertAtBack

      // remove first node from List
      public object RemoveFromFront()
      {
         if ( IsEmpty() )
            throw new EmptyListException( name );
      
         object removeItem = firstNode.Data; // retrieve data

         // reset firstNode and lastNode references
         if ( firstNode == lastNode )
            firstNode = lastNode = null;
         else 
            firstNode = firstNode.Next;
      
         return removeItem; // return removed data
      } // end method RemoveFromFront

      // remove last node from List
      public object RemoveFromBack()
      {
         if ( IsEmpty() )
            throw new EmptyListException( name );

         object removeItem = lastNode.Data; // retrieve data

         // reset firstNode and lastNode references
         if ( firstNode == lastNode )
            firstNode = lastNode = null;
         else 
         {
            ListNode current = firstNode;

            // loop while current node is not lastNode
            while ( current.Next != lastNode )   
               current = current.Next; // move to next node

            // current is new lastNode
            lastNode = current;
            current.Next = null;
         } // end else

         return removeItem; // return removed data
      } // end method RemoveFromBack

      // return true if List is empty
      public bool IsEmpty()
      {
         return firstNode == null;
      } // end method IsEmpty

      // output List contents
      public void Print()
      {
         if ( IsEmpty() ) 
         {
            Console.WriteLine( "Empty " + name );
            return;
         } // end if

         Console.Write( "The " + name + " is: " );

         ListNode current = firstNode;
      
         // output current node data while not at end of list
         while ( current != null ) 
         {
            Console.Write( current.Data + " " );
            current = current.Next;
         } // end while

         Console.WriteLine( "\n" );
      } // end method Print
   } // end class List

   // class EmptyListException declaration
   public class EmptyListException : ApplicationException
   {
      public EmptyListException( string name )
         : base( "The " + name + " is empty" )
      {
      } // end constructor
   } // end class EmptyListException
} // end namespace LinkedListLibrary

/**************************************************************************
 * (C) Copyright 1992-2006 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/

I hope I uploaded correctly, I did use "

"  "

" on each end of the code. Without the parens of course.

// Fig. 25.13: StackInheritanceLibrary.cs
// Implementing a stack by inheriting from class List.
using System;
using LinkedListLibrary;

namespace StackInheritanceLibrary
{
   // class StackInheritance inherits class List's capabilities
   public class StackInheritance : List
      
   { 
      // pass name "stack" to List constructor
      public StackInheritance()
         : base( "stack" )
      {
      } // end constructor

      // place dataValue at top of stack by inserting 
      // dataValue at front of linked list
      public void Push( object dataValue )
      {
         InsertAtFront(dataValue);
      } // end method Push

      // remove item from top of stack by removing
      // item at front of linked list
      public object Pop()
      {
         return RemoveFromFront();
      } // end method Pop
   } // end class StackInheritance
} // end namespace StackInheritanceLibrary

/**************************************************************************
 * (C) Copyright 1992-2006 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/

I did use the code /code with brackets, hope I am using them correctly for my code, if not my apologies to all.

Now for the Program.cs which is my part that is giviing me my problems. My errors are:
Error 1 'StackInheritanceLibrary.StackInheritance' does not contain a definition for 'Count' C:\Users\Wade\CSU\istk2313C#\classwork\HW2\HW2\Program.cs 70 39 HW2

Error 2 Operator '+=' cannot be applied to operands of type 'long' and 'method group' C:\Users\Wade\CSU\istk2313C#\classwork\HW2\HW2\Program.cs 72 17 HW2

Error 3 Cannot convert method group 'GetType' to non-delegate type 'long'. Did you intend to invoke the method? C:\Users\Wade\CSU\istk2313C#\classwork\HW2\HW2\Program.cs 72 23 HW2


Thank you

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using LinkedListLibrary;
using StackInheritanceLibrary;


namespace HW2
{
    class Program
    {
        static void Main(string[] args)
        {
            StackInheritance stack = new StackInheritance();
            Stack myStack = new Stack();
            Random r = new Random();
            DateTime start_SI = DateTime.Now;
                        
            for (int i = 0; i < 10000; i++)
            {
                stack.Push(r.Next(1000));
            }
            long sum = AddAllListElements(stack);
            Console.WriteLine("The sum is: " + sum);
            for (int i = 0; i < 1000; i++)
            {
                stack.Pop();
            }

            DateTime end_SI = DateTime.Now;

            TimeSpan time_consumed_SI = end_SI.Subtract(start_SI);

            Console.WriteLine("Time to insert elements via STACKINHERITANCE = " + time_consumed_SI.TotalMilliseconds);

            DateTime start_SL = DateTime.Now;

            for (int i = 0; i<10000; i++)

            {
                myStack.Push(r.Next(1000));
 
            }

            long nextsum = AddAllElements(myStack);

            Console.WriteLine("The sum is: " + nextsum);

            for (int i = 0; i < 10000; i++)
            {
                myStack.Pop();

            }



            DateTime end_SL = DateTime.Now;

            TimeSpan time_consumed_SL = end_SL.Subtract(start_SL);

            Console.WriteLine("Time to insert elements via STACKLIST = " + time_consumed_SL.TotalMilliseconds);



        }
        private static long AddAllListElements(StackInheritance stack)
        {
            long rv = 0;
            for (int i = 0; i < stack.Count; i++) 
            {
                rv += stack.GetType;
            }
            return rv;
        }

        private static long AddAllElements(Stack myStack)
        {
            long rv = 0;
            for (int i = 0; i < myStack.Count; i++) 
            {
                rv += (int)myStack.Count;
            }
            return rv;
        }

        private static void PrintArrayList(Stack myStack)
        {
            foreach (object o in myStack)

                Console.WriteLine(o); 
            
        }

        
    }
}

Oops and I forgot to change this back:

from

rv += stack.GetType;

to

rv += stack.Count;

Here is an example code of how it should work, but in my homework portion I am not getting the correct calculations to show either.

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace _313_spring_lecture_x
{
    class Program
    {
 
        static void Main(string[] args)
        {

            Random r = new Random();
            ArrayList myArrayList = new ArrayList();
            List<int> myList = new List<int>();
            DateTime start_L = DateTime.Now;
            for (int i = 0; i < 100000; i++)
            {
                myList.Add(r.Next(1000));
            }
            long sum = AddAllListElements(myList);
            Console.WriteLine("The sum is: " + sum);
            for (int i = 0; i < 100000; i++)
            {
                myList.RemoveAt(0);
            }

            DateTime end_L = DateTime.Now;

            TimeSpan time_consumed_L = end_L.Subtract(start_L);

            Console.WriteLine("Time to insert elements via LIST = " + time_consumed_L.TotalMilliseconds);

            DateTime start_AL = DateTime.Now;

            for (int i = 0; i<100000; i++)

            {
                myArrayList.Add(r.Next(1000));
            }
            sum = AddAllElements(myArrayList);
            Console.WriteLine("The sum is: " + sum);

            for (int i = 0; i < 100000; i++)
            {
                myArrayList.RemoveAt(0);
            }

            DateTime end_AL = DateTime.Now;

            TimeSpan time_consumed_AL = end_AL.Subtract(start_AL);

            Console.WriteLine("Time to insert elements via ARRAYLIST = " + time_consumed_AL.TotalMilliseconds);

 //           PrintArrayList(myArrayList);


        }

        private static long AddAllElements(ArrayList myArrayList)
        {
            long rv = 0;
            for (int i = 0; i < myArrayList.Count; i++)
            {

                rv += (int)myArrayList[i];
            }
            return rv;
        }

                    private static long AddAllListElements(List<int> myList)
        {
            long rv = 0;
            for (int i = 0; i < myList.Count; i++)
            {

                rv += myList[i];
            }
            return rv;

        }

        private static void PrintArrayList(ArrayList myArrayList)
        {
            foreach (object o in myArrayList)
                Console.WriteLine(o); 
            
        }

O.K. This assignment has been uploaded to my Professor. I have as of yet to get it working correctly,even if my grade is severly lacking for this assignment. but at least something is better than nothing.

If any one here though can still help me with what I have screwed up it would be greatly appreciated.
Thank you,
Wade McBeth

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.