View Single Post
  #1 (permalink)  
Old July 10th, 2006, 08:59 AM
Nick Y Nick Y is offline
Authorized User
 
Join Date: May 2006
Location: Iver, Bucks., United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default LinkedList<T>, AddTail, EX9_22, pages 557-559

An error caused by use of AddTail(), which I think can only be used with integers.
The following is returned when compiling EX9_22:

error C2039: 'AddTail' : is not a member of 'System::Collections::Generic::LinkedList<T>'
        with
        [
            T=double
        ]


The solution is to replace AddTail() with AddLast()

AddTail is in the 'Code from the book' and hence EX9_22 fails to compile.

=====================
Hence: Page 557 would appear to be incorrect with regards references to both AddHead() and AddTail(), which require integers. Replace respectively with AddFirst() and AddLast() for doubles.

You could add values to the list like this:

       for(int i = 0 ; i<1000 ; i++)
       values->AddLast(2.5*i);

The AddLast() function adds an item to the end of the list. You can add items to the beginning of the list by using the AddFirst() function. Alternatively, you can use the AddHead() and AddTail() functions
to do the same things.


=====================
Page 559 (EX9_22)
Change from

// Using LinkedList<T>
  Console::WriteLine(L"\nCreating a LinkedList<T> of double values:");
  LinkedList<double>^ values = gcnew LinkedList<double>;
  for(int i = 0 ; i<1000 ; i++)
  values->AddTail(2.5*i);


to

 // Using LinkedList<T>
  Console::WriteLine(L"\nCreating a LinkedList<T> of double values:");
  LinkedList<double>^ values = gcnew LinkedList<double>;
  for(int i = 0 ; i<1000 ; i++)
  values->AddLast(2.5*i);

=====================

Additionally: Page 561, third paragraph should replace AddTail() with AddLast() and hence ignore the sentence following ('You could equally well use the AddLast() function to do the same thing.')