Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Linked List In this program you will create a linked list. Each node will have t

ID: 3814793 • Letter: L

Question

Linked List

In this program you will create a linked list. Each node will have the following information:

Employee Number

First name

Last Name

Age

This program will have the following functions:

Display List

List the entries in the nodes.

Add Employees

Create new nodes in the list

Change Employee info

Edit and change information in a node in the list

User must specify the Employee number

Produce a meaningful message if the employee number is not in the list

All numeric input must be validated.

Delete Employees :

remove the node from the list.

Do not forget that if a node is removed from the middle you must reconnect the prior node with the next node.

Count List :

This function will count the number of items in a linked list NOT including the Head. Display the following message:

NNNN has a linked list with ### entries.

where NNNN is your first and last name and ### is the number of entries

e.g. John Smith has a linked list with 4 entries.

Explanation / Answer

#include #include #include #include struct node { int Empno,age; char Firstname[20]; char lastname[20]; struct node *next; }; struct node *head = NULL; struct node *current = NULL; //display the list void printList() { struct node *ptr = head; printf(" [ "); //start from the beginning while(ptr != NULL) { printf("(%d,%s,%s,%d) ",ptr->Empno,ptr->Firstname,ptr->lastname,ptr->Age); ptr = ptr->next; } printf(" ]"); } //insert link at the first location void insertFirst(int Empno, char Firstname[],char lastname[], int Age ) { //create a link struct node *link = (struct node*) malloc(sizeof(struct node)); link->Empno = Empno; link->Firstname = Firstname; link->lastname=lastname; link->Age=Age; //point it to old first node link->next = head; //point first to new first node head = link; } //delete first item struct node* deleteFirst() { //save reference to first link struct node *tempLink = head; //mark next to first link as first head = head->next; //return the deleted link return tempLink; } //is list empty bool isEmpty() { return head == NULL; } int length() { int length = 0; struct node *current; for(current = head; current != NULL; current = current->next) { length++; } return length; } //find a link with given key struct node* find(int Empno) { //start from the first link struct node* current = head; int c; char a[20],b[20]; //if list is empty if(head == NULL) { return NULL; } //navigate through list while(current->Empno != Empno) { //if it is last node if(current->next == NULL) { return NULL; } else { //go to next link current = current->next; } printf("enter the updated details of employee") ; scanf("%s,%s,%d",a,b, & c) ; current->Firstname=a; current->lastname=b; current->Age=c; } //after data modified , return the current Link return current; } //delete a link with given key struct node* delete(int key) { //start from the first link struct node* current = head; struct node* previous = NULL; //if list is empty if(head == NULL) { return NULL; } //navigate through list while(current->key != key) { //if it is last node if(current->next == NULL) { return NULL; } else { //store reference to current link previous = current; //move to next link current = current->next; } } //found a match, update the link if(current == head) { //change first to point to next link head = head->next; } else { //bypass the current link previous->next = current->next; } return current; } main() { insertFirst(1,Gahanna, Hansen, 25); insertFirst(2,kajsjsj, Heineken, 30); insertFirst(3,hdhdjsj, hdhihjsj, 23); insertFirst(4,hdjsjsjajs,hsjjsjsksjs,25); insertFirst(5,bdjjkaka,bdndnjskak,32); insertFirst(6,bsnjakaka,hdjjdjdjs,26); printf("Original List: "); //print list printList(); while(!isEmpty()) { struct node *temp = deleteFirst(); printf(" Deleted value:"); printf("(%d,%d) ",temp->key,temp->data); } printf(" List after deleting all items: "); printList(); printf(" "); struct node *foundLink = find(4); if(foundLink != NULL) { printf("Element found: "); printf("(%d,%d) ",foundLink->key,foundLink->data); printf(" "); } else { printf("Element not found."); } delete(4); printf("List after deleting an item: "); printList(); printf(" "); foundLink = find(4); if(foundLink != NULL) { printf("Element found: "); printf("(%d,%d) ",foundLink->key,foundLink->data); printf(" "); } else { printf("Element not found."); } printf(" "); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote