1

I have studied many example related to linked list example but they just explain in simple way using only one structure type. So i need to dig more to clear my doubts:

    struct movies_t {
    int number;
    string title;
    int year;
    movies_t *next; 
    }
  • Does all of the nodes of a linked list necessarily should be of movies_t type (as its in array:array is a collection of values of similar type) ?

  • If i want to add a one or several more different new structure dynamically and those contains completely different elements except the int number; which is a common element in all data structure to sort data orderly. Is it possible ?

  • If I have to implement nested data structures(given below), would it be possible to do it with Linked list or with some tree data structure (Binary, B, B+ trees )?

    struct movies_t {
    int number;
    string title;
    int year;
    }
    
    struct friends_t {
    int number;
    string name;
    string email;
    movies_t favorite_movie;
    }
    
    struct world_t {
    int number
    string country;
    string continent;
    double population
    movies_t favorite_movie;
    friends_t friends_forever;
    }
    
User
  • 619
  • 1
  • 9
  • 24

1 Answers1

0

You can create a class rather structure for node. Do the following,

class parent_t{
int number;
parent_t* next;
}

class movies_t: public parent_t {
string title;
int year;
}

class friends_t : public parent_t {
string name;
string email;
movies_t favorite_movie;
}

class world_t: public parent_t {
string country;
string continent;
double population
movies_t favorite_movie;
friends_t friends_forever;
}

Now, you can create the linked-list of parent_t type. Then you can insert the movie_t, friends_t, world_t type objects into the linked-list.

Banukobhan Nagendram
  • 2,335
  • 3
  • 22
  • 27