/*Program that utilizes a structure and linked list to store*/ /*employee information taken from the keyboard*/ /*Programmer: Class: C*/ /*Instructor: Date: April 23rd, 2007*/ /*Language: C (gcc target) #include /*Library to be included*/ #include /*Library to be included*/ #include /*Library to be included */ #define NO_EMPLOYEES 3/* Number of employees entered */ #define MAXLENGTH 21 /* the maximum length of the names */ /*Define Structure for employee*/ typedef struct employee { char firstname[MAXLENGTH];/*Max length of first name*/ char lastname[MAXLENGTH];/*Max length of last name*/ int id; /*ID declared as int*/ struct employee *next; } empl; empl* insert(empl *first, empl *new); */Main declared*/ int main(int argc, char **argv) { empl *head, *temp; int i; head=NULL; */ Information will be entered here using keyboard*/ */ It will loop 3 times */ for(i=0; ifirstname, temp->lastname, &temp->id); temp->next = NULL; head = insert(head, temp); } /* All data will printed out here that was entered*/ /*Lowest to highest ID number*/ printf("The employee with the lowest id number is\n"); printf("First name: %s\n", head->firstname); printf("Last name: %s\n", head->lastname); printf("User ID: %d\n", head->id); temp = head; printf("Here's a list with all employees\n\n"); while(temp != NULL){ printf("First name: %s\n", temp->firstname); printf("Last name: %s\n", temp->lastname); printf("User ID: %d\n", temp->id); temp = temp->next; } return 0; } empl* insert(empl *first, empl *new) { empl *cur, *prev; /* return the new node if it's the first node */ if(first == NULL) { return new; } cur = first; prev = first; /* loop until we have no next node anymore */ while(cur != NULL) { /* see if our current node has a heigher number than the number we're looking for */ if(cur->id < new->id) { prev = cur; cur = cur->next; } else { break; } } /* the first node is a special case, so we change that differently */ if(first==cur) { first = new; new->next = cur; } else { prev->next = new; new->next = cur; } return first; }