The function insert of the class orderedLinkedList does not check if the item to
ID: 3626412 • Letter: T
Question
The function insert of the class orderedLinkedList does not check ifthe item to be inserted is already in the list; that is, it does not ch eck for
duplicates. Rew rite the defini tion of the function insert so that before
inserting the item, it ch ecks wh ether the item to be inserted is already in the
list. If the item to be inserted is already in the list, the function outputs an
appropriate error message. Also , write a program to test your function.
Explanation / Answer
Add in this code: struct node *q; q = start //assuming "start" refers to the start of the list. while (q != NULL) { if (item == q.value) { printf("Found"); return 0; } q= q->next; } This will check whether the item to be inserted is already present. To test it, just implement a linked list and run the function.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.