0

It is posible in a linked list implementation,the nod to hold more then one information ? for exemplei want the node to hold a person`s name,adress,country,etc....

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Narue
0

generally if you want the node to hold multiple pieces of data then you should create a class or struct that would hold all of that data and then have the node in the linked list point to a instance of that object.

class Foo
{
    int a,b,c,d;
};

int main()
{
    List<Foo*> bar;
    Foo * one, *two;
    bar.insert(one);
    bar.insert(two);
}
0

It is posible in a linked list implementation,the nod to hold more then one information ?

It can hold whatever you want. You're the programmer after all. :icon_rolleyes: However, since most linked list libraries are fairly generic, they'll hold only one item of either template or void* type and that item can be an aggregate type:

#include <list>
#include <string>

int main()
{
    class dude
    {
        std::string name;
        std::string address;
        std::string country;
    };

    std::list<dude> mylist;

    // ...
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.