mardi 14 décembre 2021

how to fill a doubly linked list from input file text

The structure Company is a doubly linked list of all the employees. Write a function that parses the input text file and returns the doubly linked list of all the employees in your input text file. This function should pay particular attention to correctly build the ‘Calendar’ and the ‘List of Attendees’ for each scheduled appointment.

struct Employee { 
    int UniqueID;
    char FirstName[30], LastName[30], EmailAddress[50]; 
    Attendee *myAtt;
    Employee *next;
    Employee *previous; 
};

struct Attendee { 
    Employee *self;
    Attendee *next;
};

struct Company {
    Employee *Head, *Tail;
};

struct Time {
    int Day, Hour, Minute, Second;
};

struct Appointment { 
    char Title[50];
    Time StartingTime;
    int Duration;
    Attendee *ListOfAttendees; 
    Appointment *next;   
};

Employee* push(struct Employee* head, struct Employee* node1, struct Employee* node2) {

    struct Attendee* a1 = new Attendee;
    struct Attendee* a2 = new Attendee;
    struct Employee* temp1 = node1;
    struct Employee* temp2 = node2;
    struct Attendee* p = new Attendee;
    struct Attendee* p1 = new Attendee;
    Company* c;

    if (head == NULL)
    {

        a1->self = node2;
        a1->next = NULL;

        node1->myAtt = a1;
        node1->previous = NULL;
        node1->next = node2;
        node2->next = NULL;
        node2->previous = node1;
        a2->self = node1;
        a2->next = NULL;
        
        head = node1;
    }
    else
    {
        int counteratt1 = 0;
        Employee* em = head;
        int counteratt2 = 0;
       
        while (em->next != NULL)
        {
            if (em->FirstName == node1->FirstName && em->LastName == node1->LastName) {
                counteratt1++;
                
            }
            if (em->FirstName == node2->FirstName && em->LastName == node2->LastName) {
                counteratt2++;
                
            }
            em = em->next;
           

        }


        if (counteratt1 == 0)
        {
            a1->self = node2;
            a1->next = NULL;
            node1->myAtt = a1;
            node1->next = head;
            node1->previous = NULL;
            head->previous = node1;
            head = node1;
           
        }
        if (counteratt2 == 0)
        {
           
           a2->self = node1;
            a2->next = NULL;
            node2->next = head;
            node2->myAtt = a2;
            node2->previous = NULL;
            head->previous = node2;
          
            head = node2;
            head->myAtt->next = NULL;
           
        }
        else
        {

            struct Employee* k = head;
            while (k != NULL)
            {
                if (k->FirstName == node1->FirstName && k->LastName == node1->LastName)
                {
                    p = k->myAtt;
                    a1->self = node2;
                    while (p->next != NULL) {
                        p = p->next;
                    }
                    p->next = a1;
                    a1->next = NULL;
                }
                if (k->FirstName == node2->FirstName && k->LastName == node2->LastName)
                {
                    p1 = k->myAtt;
                    a2->self = node1;
                    while (p1->next != NULL) {
                        p1 = p1->next;
                    }
                    p1->next = a2;
                    a2->next = NULL;
                }
                k = k->next;
                //

            }
        }

    }
   
    return head;
}

Aucun commentaire:

Enregistrer un commentaire