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

Write an algorithm USING A LINKED LIST called STUDENT to enter a student’s Name,

ID: 3876032 • Letter: W

Question

Write an algorithm USING A LINKED LIST called STUDENT to enter a student’s Name, Age, Student ID Number and Nationality input from the keyboard. The linked list will have a variable number of nodes. The number of nodes will grow as a new student’s data is entered. The number of nodes will shrink as a student’s data is erased. There will be an option to display the entered data on the screen. The algorithm will also print the following menu and provide the following selections: --------------------------------------------- Press 1 to INSERT a new person’s record into the list Press 2 to DELETE an existing person’s record from the list Press 3 to DISPLAY the list of records on the screen Press 4 to EXIT --------------------------------------------- Draw a flowchart of your algorithm using Microsoft Visio’s flowcharting symbols. Convert your algorithm into a C-Program, compile and run it before you present it to the course assistant Faegheh Yeganli in the EENG212 Computer Lab. Your homework will be check for successfully compiling and running, the sense of algorithmic approach and flowcharting. Hint: Your program will have two functions which are called, enter_new_data and remove_existing_data

Explanation / Answer

C PROGRAM.

struct Student

{

char name[10];

int age;

int id;

char nationality[10];

struct Student * next;

};

void enter_new_data(struct Student ** head_ref,char name,int age,int id,char nationality) //adds a node in the beginning of the linked list.

{

struct Student * newNode=(struct Student *)malloc(sizeof(struct Student));

newNode->name=name;

newNode->age=age;

newNode->id=id;

newNode->nationality=nationality;

newNode->next=(*head_ref);

(*head_ref)=newNode;

}

void remove_existing_data(struct Node **head_ref, int key) //deletes the particular node with key.

{

struct Node* temp = *head_ref, *prev;

if (temp != NULL && temp->data == key)

{

*head_ref = temp->next;

free(temp);

return;

}

while (temp != NULL && temp->data != key)

{

prev = temp;

temp = temp->next;

}

if (temp == NULL)

return;

prev->next = temp->next;

free(temp);  

}

void display(struct Student *n)

{

while(n!=NULL)

{

printf("%s",n->name);

printf("%d",n->age);

printf("%d",n->id);

printf("%s",n->nationality);

n=n->next;

}

}

int main()

{

struct Student *head=NULL; //assume the linked list is empty.

int i;

printf("Enter 1.insert 2.delete 3.display 4.exit");

printf("%d",&i);

switch(i):

case 1:

enter_new_data(GIVE THE VALUES AS PER REQUIRED);//call insert method.

break;

case 2:

remove_existing_data(GIVE THE VALUES AS PER REQUIRED);//call delete method.

break;

case 3:

display();

break;

case 4: printf("EXIT....");

break;

default:printf("ERROR.....");

}

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