CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2002
    Posts
    7

    Question Need help with LinkList

    Got a class in which I need a double LinkList (X). This DLList X has another DoubleLinkList (Y) within its nodes.

    Now I'm using STL List.h template. The issue I'm facing maybe very simple for you but a little confusing for me..... Hoping that someone can help me with it.

    class Paul
    {

    public: Paul(); //Construction
    ~Paul(); //Destructor
    CreateList();

    private:
    typedef struct XNode
    {
    long country;
    list <CString> csCities;
    };
    list <XNode> XList,
    }

    Question:
    a) how will I initialise this XList?
    b) If I want to pass this xList as a ref variable in a funtion, how will that be done?
    c) how will I create a new XNode? Basically, anything especial I have to do for csCities list creation?
    c) How will the destructor work?

    Thanks for your kind perusal.

  2. #2
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    Basically, it all just works. My guess is that your main confusion has to do with notation. What I always do is typedef the templated items as follows:

    typedef std::list<CString> MyCStringList;
    typedef MyCStringList::iterator MyCStringListIter;
    typedef MyCStringList::const_iterator MyCStringListConstIter;

    This way, you don't need to use the template parameter when accessing the class.

    a) how will I initialise this XList?
    It's initialized as soon as the class is initialized.

    b) If I want to pass this xList as a ref variable in a funtion, how will that be done?
    Simply pass it. The argument type would be CXNodeList& if you typedef as I described above.

    c) how will I create a new XNode? Basically, anything especial I have to do for csCities list creation?
    Nothing special needed.

    c) How will the destructor work?
    It will work just fine.

    Jeff

  3. #3
    Join Date
    Jan 2002
    Posts
    7
    Thanks Jeff,
    Ur typedef has made it simpler to see the structure and has helped me. You are also right in mentioning that I'm getting confused with the notations.

    Couple of questions though....
    a) when I'm creating a new XNode for the XList, how would I create the csCities linkedlist?

    typedef std::list<XNode> MyNodeList
    MyNodeList nList;

    XNode xTemp;
    xTemp.country = 12;

    xTemp.csCities->list(); //error for creating list here

    nList.push_front(xTemp);

    b) How does iteration work? How would I traverse the node and check for country?

    I know it would be simple but I'm lost... Is there any place from where I can reference examples for using this STD::list?

    thanks for everyones time for coming here and seeing the possibilty of helping. Especial thanks to Jeff for taking the time to actually answering my questions.

  4. #4
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    The csCities linked list is created when you createteh XNode, although it will of course be empty.

    You add items as follows:

    xTemp.csCities.push_back("Chicago");

    to iterate through the list, you would do:

    Code:
    for( MyCStringListConstIter iter = xTemp.csCities.begin(); iter != xTemp.csCities.end(); ++iter )
    {   
         CString cityName = *iter;
         ...
    }
    I understand your confusion. It is somewhat difficult to learn. MSDN documentation is difficult and the source code is worse. Somebody else would be better at recommending a book--I started using STL on an SGI computer when there were no decent books available, at least none that I found. It was rather frustrating.

    Stroustrup's book is good as a reference, but not necessarily to learn from.

    Anybody have a book recommendation for an STL book?

    Jeff

  5. #5
    Join Date
    Mar 2000
    Location
    Seattle , WA
    Posts
    87
    The C++ Standard Library -- Josuttis

  6. #6
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    Matthew Austern's book is good as a reference, and Paul MacKenzie recommends Josuttis's book (I've not read it). Definitely read "Effective STL" by Scott Meyers.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  7. #7
    Join Date
    Jan 2002
    Posts
    7
    Thanks everyone......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured