Help with structs...more specifically, linked lists - Eek, please help me!

This is a discussion on Help with structs...more specifically, linked lists - Eek, please help me! within the C++ Programming forums, part of the General Programming Boards category; struct ListElement { RECT arect; ListElement* pNextListElement; }; SOmeone please explain this? Also, why would an object in this struct ...

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    Help with structs...more specifically, linked lists - Eek, please help me!

    struct ListElement
    {
    RECT arect;
    ListElement* pNextListElement;
    };

    SOmeone please explain this? Also, why would an object in this struct be the type of RECT which is a different structure? Also, what does the pointer pointing to this struct do here? How does this work and why?

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    from your title i see u're working on the linked list...

    an educated guess.... the code that you posted stands for a so called "Node", which ties the linked list together...

    to make the long story short.... think of it this ....

    --- bunch of such "struct" each containing similar attributes...(an object and a pointer to another node)

    --- think of a "Railroad" .... Railraod track and and your Stations are your "linked lists" ... the tracks "link" to your stations (NODES) ... in your stations "NODES" you can have a BAGEL STORE (your object of another class).... or even more or different type of data...(Burger King)....

    hope this short analogy helps....

    Regards,
    matheo917

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Basically, this code is the base for a linked list of RECT's, whatever they might be. Therefore, every single item in the list will each have the properties of a RECT.

    The pointer is currently pointing to nothing. However, if you were making a linked list, it would eventually point to a new(on free store) ListElement

    By the way, when thinking of linked lists, think of them as the following. Each object is created inside the previous object and the previous object is needed. So instead of being like this


    head----->item 1----->item 2---->and so on

    think of it as this


    Code:
    \         head            / 
       \     item 1       /   
          \  item 2    /

    When I think of them this way, it helps me out much more then of just simply considering them to be objects pointing to other objects.

    I hope this helps u and good luck.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    32
    Have a look here: http://www.doc.ic.ac.uk/~wjk/C++Intr...erL7.html#S7-5 It explains in a good way how linked lists work and has got illustrations. This site helped me to understand the concept.

    Seron

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 05:32 PM
  2. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 11:32 PM
  3. Replies: 2
    Last Post: 01-18-2003, 01:32 AM
  4. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 09:57 PM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 07:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21