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....

Recommended Answers

All 2 Replies

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);
}

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;

    // ...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.