sub list of linked list in c? -


i want make sub list in single list using c. have list name, surname, phone, e-mail…. want make sub list under phone keep more phones. struct:

typedef struct ph{     char * phone;     ph *next; }listofphones;  typedef struct client{     char* name;     char* surname;     date birthday;     char bankaccount[16];     listofphone phone;     char* mail;     struct client *next; } clientdata;     

i want sub-list client. problem phones in same list. how can create different list?

example:

name1->surname1->birthday1->bankaccount1->phone1->mail1.......                                             |                                           phone2                                             |                                           phone3                                              .                                             .                                                                                                  . 

(sorry bad drawing hope it’s clear enough.)

you need keep head of other list in every node of list. structure definition like:

typedef struct ph{     char * phone;     ph *next; }listofphones;  typedef struct client{     char* name;     char* surname;     date birthday;     char bankaccount[16];     ph* phhead;     char* mail;     struct client *next; } clientdata;   

and now, have list inside list. however, writing code traverse, find, enumerate phone numbers client require double pointer indirections should better avoided. if have finite number of phone numbers client, can change like:

typedef struct client{     char* name;     char* surname;     date birthday;     char bankaccount[16];     char phnumbers[5][10];     char* mail;     struct client *next; } clientdata;   

the above definition of struct assumes there maximum of 5 phone numbers per client , every phone number have @ 10 characters. can change needs.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -