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 = NULL;
- //_head->employee = initEmployee
- }
- int addEmployee(struct Node* _head, char _firstName[256], char _lastName[256], int _age, int _sinNum, char _status){
- struct Node *newNode;
- newNode = (struct Node*)malloc (sizeof(struct Node));
- //newNode->next =NULL;
- //initilizes the new node with the employee data
- strcpy(newNode->employee.firstName, _firstName);
- strcpy(newNode->employee.lastName, _lastName);
- newNode->employee.age = _age;
- newNode->employee.sinNumber = _sinNum;
- newNode->employee.status = _status;
- //tranverse to the end of the list
- if (_head == NULL){
- _head = newNode;
- return 1;
- }
- struct Node* current;
- current = (struct Node*)malloc (sizeof(struct Node));
- //current = _head;
- for (current = _head; current->next!=NULL;current = current->next);
- /*while(current!=NULL){
- current = current->next;
- }*/
- current->next = newNode;
- return 1;
- }
- /*
- int getnode(){
- }
- int removeEmployee(){
- }*/
- /*int Reapeated(struct Node* _head, int _times){
- }*/
- void DeleteExpt(struct Node* _head, char _lastName[256]){
- struct Node *newHead;
- newHead = (struct Node*) malloc (sizeof(struct Node));
- struct Node *current;
- current = (struct Node*) malloc (sizeof(struct Node));
- int count = 0;
- while(_head->next!=NULL){
- if (strcmp(_head->employee.lastName, _lastName)==0 && count ==0){
- newHead = _head;
- newHead->next = current;
- count++;
- }
- else if (strcmp(_head->employee.lastName, _lastName)==0){
- //struct Node *temp;
- //temp = (struct Node*) malloc (sizeof(struct Node));
- current->next = _head;
- current = current ->next;
- }
- }
- _head = newHead;
- }
- void displayList1(struct Node* _head, int _age){
- struct Node* current = _head;
- while(current->next !=NULL){
- if (current->employee.age > _age)
- //displayEmployee
- printf("%s, %s\n%d\n%d\n%c\n", current->employee.lastName, current->employee.firstName, current->employee.age, current->employee.sinNumber, current->employee.status);
- current = current->next;
- }
- }
- void displayList2(struct Node* _head, char _status){
- struct Node* current = _head;
- while(current->next !=NULL){
- if (current->employee.status == _status)
- //displayEmployee
- printf("%s, %s\n%d\n%d\n%c\n", current->employee.lastName, current->employee.firstName, current->employee.age, current->employee.sinNumber, current->employee.status);
- current = current->next;
- }
- }
- int main (){
- struct Node *head;
- head = (struct Node*) malloc (sizeof(struct Node));
- head = NULL;
- //initilizeList(head);
- int age;
- int sinNum;
- char firstName [256];
- char lastName [256];
- char status;
- char temp;
- for (int i =1;;i++){
- printf("Enter the first name of Employee #%d. Enter 'q' to stop entering employees.\n", i);
- scanf("%s%c", firstName, &temp);
- printf("\n%s\n", firstName);
- if (firstName == "q")
- break;
- printf("Enter his/her last name.\n");
- scanf("%s%c", lastName, &temp);
- printf("Enter his/her age\n");
- scanf("%d%c", &age, &temp);
- printf("Enter his/her SIN number\n");
- scanf("%d%c", &sinNum, &temp);
- printf("Enter the status of the employee 'a' active, 's' suspended, 't' terminated.\n");
- //status = getchar();
- scanf("%c%c", &status, &temp);
- addEmployee(head, firstName, lastName, age, sinNum, status);
- displayList1(head, 0);
- }
- displayList1(head, 50);
- displayList2(head, 'a');
- return 0;
- }
Add Comment
Please, Sign In to add comment