I should do programme in C , but I don 't know witch struct I can use.:(


question :

we have congresse , where there is 2 type of activities : activity 1 and activity 2 in each one there is many activities where many people are linked in :(


but I dont know how my struct , put in your mind that I should do all operat as insert , searche........using files but that another probleme that may be I can solved :(

look that struct that I propose but I can't understand how I can use it to do all opertor as insert ; and even that struct is very well or not ยง

struct  people
{ char name[10];
   char identity [10];
}people;
struct congress
{
char type_activity[10];
}
struct activity 
{
struct activity * next ;
char name_actvity [10];
personne * nxt ;
}

Edited 6 Years Ago by Nick Evan: Added code-tags

You need to study your textbook or google for online tutorials about linked lists. They will show you how to write functions to insert and delete nodes in the linked lists.

I know how to that but , I have probleme in the way of definition of my struct because I have congress in that there is two type type 1 and type 2 in each one there is many activities and in such activity there is many people linked in do you understand me
can you help me . not google I need

Maybe something like this:

struct person
{
    char name[40];
    struct person* next;
};

struct activity
{
   char activity_name[40];
   struct activitiy* next;
   struct person* head; // head of linked list
};

struct congress
{
    struct activity* type1; // head of type 1
    struct activity* type2; // head of type 2
};

Edited 6 Years Ago by Ancient Dragon: n/a

thinks very much . but how I can make linker between the two .ie how I can use struct person* head; it still just few time to finish my prog but I don't use the header of person how I can use it .
thinks

You use it exactly like you use the two pointers in struct congress. When you add a new node to activit1 or activity2 in struct congress, you add new person nodes to the head pointer in activities struct. The code below assumes you want to insert a new person node at the end of the linked list.

void AddPerson (struct Activity* act, struct person* p)
{
   p->next = NULL;
   if( act->head == NULL)
       act->head = p;
  else
  {
    // locate end of the linked list
    struct person* node = act->head; 
    while( node->next )
          node = node->next;
     node->next = p;
  }
}

Edited 6 Years Ago by Ancient Dragon: n/a

struct person
{
char name[40];
struct person* nextperson;
};

struct activity
{
char activity_name[40];
struct activitiy* nextactivity;
};
struct together
{
activity * p;
person * head;
};
that is the way how I define my struct ; for exemple : for the struct person I write all the function and the some for activity. it mean now I want the way haw I can write fonction to make join the activity and liste of person help me and thinks for all of you
{
struct activity* type1; // head of type 1
struct activity* type2; // head of type 2
};

what do you mean "join activity and person lists"? For each activity there is a list of persons? If that is yes, then do it like I posted.

look . I don't wante to lose all what I work it mean the functions that I do for add, delete , searche .............for struct person and the same for activity so I search fo solution that at max I can keep my work . add that in each activity there is many people it mean each person like that activity he can linked in .thinks I waite for you replay

join activity with person ie that each person like each activity he can join in . I like what do say but I dont want to lose what I have did ? please if you can help me

Sometimes original work (code) is just crappy (e.g. faulty design) and requires re-coding to make it better -- I've done it myself. If you want congress to have many activities, and each activity to have many people, they you really have no choice but to have linked lists within linked lists, something like I posted.

This is one reason to write flow charts and design documents before line 1 of the program is coded. It makes your coding job a lot easier if you know what the program should be and how to go about making it do that.

BTW: it's customary for the next pointer in linked lists to be simply named next, not nextactivitiy or nextperson. And it makes coding a little simpler too (not so much to type and easier to understand).

Edited 6 Years Ago by Ancient Dragon: n/a

Yes, I have NOT done it. Its your program not mine, so don't expect anyone to just hand you over some code. If you want me to write your program for you please deposit $1,000.00 USD in my PayPal account and give me the name/email address of your teacher. Doing your homework is not cheap :)

This article has been dead for over six months. Start a new discussion instead.