Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include // data dataToInsert; new Node->next = NULL; return newNode; else f list is not empty, let's insert at the end print f(inserting element

image text in transcribed
image text in transcribed
image text in transcribed
#include #include // data dataToInsert; new Node->next = NULL; return newNode; else f list is not empty, let's insert at the end print f("inserting element with data %dn-dataTolnsert); Node "current listHead: CAUTION while (current != NULL) { if (current->next NULL) // if it's end of list... Node "newNode -malloc(sizeof(Node)) newNode-data data Tolnsert newNode- next-NULL current->next newNode; return listHead; 3 else t otherwise... current- currentnext; void printList(Node listHead) printf"printing list: ") Node "current = lis:Head; while (current!-NULL) printf("%d ""current->data); current -current-next; printf"n"); Node* deleteFirst(Node listHead) t printf"deleting first element from list: In") l TODO: implement return listHead; Node deleteLast(Node listHead) t printf"deleting last element from list: In") TODO: implement Node deleteLast(Node listHead) printf"deleting last element from list: In TODO: implement return listHead; Node deleteSpecific(Node listHead, int data Value)t assume data to delete always exist and is always unique in / this exercise printf( "deleting %d from list in', dataValue); II TODO: implement return listHead; void printBackwardsFromZero(Node listHead) printf printing list in backwards from the first 0 element (or end of list): I TODO: implement. printf"n"): int maino Node myHead NULL; I/head of the linked list, not really MY HEAD myHead insert(myHead, 2000) myHead insert(myHead, 2018); printList(myHead); myHead-insert(myHead, 2001) myHead insert(myHead, 1998); myHead insert(myHead, 0); myHead-insert(myHead, 1999) myHead-insert(myHead, 2021) myHead insert(myHead, 2020) printList(myHead) myHead deleteFirst(myHead) printList(myHead); myHead = deleteastmyHead); printList(myHead); myHead - deleteSpecific(myHead, 1998); printList(myHead): myHead-deleteSpecific(myHead, 2018); printList(myHead); printBackwardsFromZero(myHead) return 0; Problem 2 Please try to implement the second unimplemented function deleteLast that deletes last element in the list. It will be slightly harder than deleteFirst Hint: If a node's next pointer points to NULL, it's the last node Hint 2: To delete the last node, we will point the second last element's next pointer to NULL If successful, you will see that when we call that in main, it will delete the last element and have the following output inserting first element with data 2000 inserting clement with data 2018 printing list: 2000 2018 inserting clement with data 2001 inserting element with data 1998 inserting element with data 0 inserting element with data 1999 inserting element with data 2021 inserting element with data 2020 printing list: 2000 2018 2001 1998 0 1999 2021 2020 deleting first element from list: printing list: 2018 2001 1998 0 1999 2021 2020 deleting last element from list: printing list: 2018 2001 1998 0 1999 2021

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions