Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- struct Employee{
- char firstName[256];
- char lastName[256];
- int age;
- int sinNumber;
- char status;
- };
- struct Node{
- struct Employee *employee;
- struct Node *next;
- };
- void initilizeList(struct Node** head){
- *head = (struct Node*) malloc(sizeof(struct Node));
- (*head)->next = NULL;
- //(*head)->employee = (struct Employee*) malloc (sizeof(struct Employee));
- }
- //Given a list and the data of the new employee it adds it to the end of the list
- void addEmployeeEnd(struct Node** head, char firstName[256], char lastName[256], int age, int sinNum, char status){
- struct Node *newNode;
- initilizeList(&newNode);
- //initialize employee and the data
- struct Employee *employee = (struct Employee*)malloc(sizeof(struct Employee));
- strcpy(employee->firstName, firstName);
- strcpy(employee->lastName, lastName);
- employee->age = age;
- employee->sinNumber = sinNum;
- employee->status = status;
- //link the node with the new employee struct
- newNode->employee = employee;
- //if the list is empty make it the first element
- if (*head == NULL){
- *head = newNode;
- return;
- }
- //navigate to the end of the list
- struct Node* current;
- for(current = *head;current->next!=NULL;current=current->next);
- //add newNode to the end of the list
- current->next = newNode;
- newNode->next = NULL;
- }
Add Comment
Please, Sign In to add comment