Results 1 to 10 of 10

Thread: Array of linked lists

  1. #1
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Array of linked lists

    hey there i have a linked list which is made up of integers...i would just like to know if there is a way to create an array of linked lists?? ive never tried it before so i dont really know the syntax of it...any help would be much appreciated thanks. Jag

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Array of linked lists

    Sure its possible.
    Could you post the defintion code of your list?

  3. #3
    Join Date
    Mar 2006
    Posts
    22
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Array of linked lists

    Are you using a vector<int> for your linked list?

    If so, if you want an array:
    Qt Code:
    1. vector<int> array[] = {
    2. vector<int> a,
    3. vector<int> b
    4. };
    5.  
    6. // Insert into a.
    7. array[0].push_back(1);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Array of linked lists

    ok thanks for the advice - i was meant to post up my linked list but i used vectors to do it so i guess that way would work. cheers

  5. #5
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Array of linked lists

    hey there i tried the code that was posted above for the array of linked lists but i keep gettin compilation errors from it. the error message says forbids declaration of no type and expected ; before < token. any idea's??

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Array of linked lists

    Add "std::" in front of "vector" and next time, please, post the exact error message.

  7. #7
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Array of linked lists

    Ok i tried that too but it still doesnt work.im creating the vector in my header file underneath private: is that right? heres my new error message:
    Attached Images Attached Images

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Array of linked lists

    Could you post the code?

  9. #9
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Array of linked lists

    Qt Code:
    1. private:
    2.  
    3. std::vector<int> array[] = {
    4. vector<int> a,
    5. vector<int> b
    6. };
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Array of linked lists

    You can't initialize member variables like this.

    Try:
    Qt Code:
    1. typedef std::vector<int> Vector;
    2.  
    3. class Test
    4. {
    5. // ...
    6. private:
    7. static const int SIZE = 2;
    8. Vector array[ SIZE ];
    9. };
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to jacek for this useful post:

    therealjag (9th March 2006)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.