http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linked Lists part 2




>He then said that the following segment creates a dynamic linked list with
>the values
>12.8
>45.2
>70.1
>
>head=new nodeType; // Huh?

You're creating the the first element which is a pointer to the entire list.
This is how you will refer to the link list in future.

>head->component=12.8; // Isn't this just *head.component=12.8;

Basically, but since head is a pointer you can use the -> operator.  I'm not
sure if you can do it the other way or not.

>newNodePtr=new nodeType; // Again Huh?
get the first element in the link list.  Head points to here.  An empty list
is just a head that doesn't point anywhere, anytime you add an element you
have to dynamically create the next element so it can resize and hold your
item.

>newNodePtr->component=45.2;
>head->link=newNodePtr; // Is this referring the link on??

Yep. Referring it to the next element
>newNodePtr=new nodeType; // Why again??
>newNodePtr->component=70.1; // Okay

Same as above.
>currPtr->link=newNodePtr; // Huh, where did currPtr come into things

I assume currPtr is defined in the .h file as some pointer to node.  If not,
it appears to declare the next node in the list (?).
>newNodePtr->link=NULL; // Okay, help

Setting the last node's link to the next link to NULL or 0 which will
signify the end of the list so when you traverse it in some loop you have an
exit condition (eg do until node->link != NULL)

>currPtr=newNodePtr; // Lost again
Again I'm not sure if I have everything here, not sure.

I'm fairly new to the LList myself but I figured I'd take a stab at the few
parts I am familiar with.  Hopefully I'm not too far off with this.  If I am
someone will surely tell me. ;)

You might want to get a basic C++ book to make this easier on you.  There
are many examples of linked lists on the 'net and a book on data structures
would probably go into exhaustive detail on the subject.

Good luck,

Jim

=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html