Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Delete first element containing a specific string from a linked list Download l i s t d e l e t e c o n
Delete first element containing a specific string from a linked list
Download tring. here, copy your CSE account using the following command:
ctivitietrintring.
Your task add code this function tring.:
Delete the first node the list containing the specific string
The deleted node freed.
node contains the specified string, the list not changed
The head the list returned.
struct node ontains stringIZE struct node
return NULL;
Note tring. uses the following familiar data type:
struct node
struct node ;
char dataIZE;
;
ontains given two argument, value and head.
data a string with max size characters
head the pointer the first node a linked list
The function designed delete the first node the linked list that contains a specific string.
Add code ontains that deletes the first node the linked list that whose data field equals a specified string and returns a pointer the new list.
data does not occur the linked list, the list should not changed.
data occurs more than once the linked list, only the first occurrence should deleted. Note, the list now empty ontains should return NULL.
ontains should call free free the memory the node deletes.
Testing
ontains. also contains a main function which allows you test your ontains function.
This main function:
takes command line arguments
converts the command line inputs a linked list,
assigns a pointer the first node the linked list head,
reads a sstring from standard input and assigns data,
calls ontains head and
prints the result.
not change this main function. you want change you have misread the question.
you're trying leakcheck your code locally and getting errors you'll need free the entire list the end your main function! You can run leakcheck adding the leakcheck option your command leakcheck irst.irst Check the updated code sample
Your ontains function will called directly marking. The main function only let you test your ontains function
tring.tring
tring cats sleep hours per day
Enter a string delete: cats
hours, per, day
tring the bumblebee bat the worlds smallest mammal
Enter a string delete: bumblebee
bat, the, worlds, smallest, mammal
tring
Enter a string delete: hello
tring there are parts Africa all four hemispheres
Enter a string delete: four
are, parts, Africa, all, hemispheres
tring the most money ever paid for a cow auction was million dollars
Enter a string delete: dollars
most, money, ever, paid, for, cow, auction, was, million
Assumptionestrictionlarifications
ontains should call free free the memory for the node deletes
ontains should not change the data fields list nodes.
ontains should not use arrays.
ontains should not call malloc.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started