Question
Program linked list and implement a searching algorithm to search through it's values. Part 1: a Linked List Make a linked list that can accept
Program linked list and implement a searching algorithm to search through it's values.
Part 1: a Linked List Make a linked list that can accept any integer number from the user. Continue to ask the user for more integers until they say they are done. [2 pts]
Ex. Enter an integer value for your list: 12
Would you like to add more values? ("y" or "n") y
Enter an integer value for your list: 46
Would you like to add more values? ("y" or "n") n
Prompt the user for the value they would like to search for in the list. Tell them if their value was found in the list or not. Continue to prompt them for more searches until they say they are done. [2 pts]
Ex. Please enter an integer value to search for in the list: 21
Sorry, your value, 21, was not found :-( Would you like to search for another value? ("y" or "n") y
Please enter an integer value to search for in the list: 46
Your value, 46, was found in the list! :-D Would you like to search for another value? ("y" or "n") n
Part 2: Searching Algorithm Choose a searching algorithm to program. [3 pts] NOTE: you can use your class lecture material, zybooks and other resources like GeeksForGeeks, etc., just make sure you understand it line by line, since you will be needing to comment on each line (see "Comments Required" below).
Choose any one from below:-Linear Search algorithm: 1. Traverse the array using a forloop. 2. In every iteration, compare the target value with the current value of the array. a. If the values match, return the current index of the array. b. If the values do not match, move on to the next array element. 3. If no match is found, return -1.
-Binary Search algorithm:1. Start with the middle element: a. If the target value is equal to the middle element of the array, then return the index of the middle element.
b. If not, then compare the middle element with the target value, i. If the target value is greater than the number in the middle index, then pick the elements to the right of the middle index, and start with Step 1. ii. If the target value is less than the number in the middle index, then pick the elements to the left of the middle index, and start with Step 1. 2. When a match is found, return the index of the element matched. 3. If no match is found, then return -1
Comments Required To demonstrate that you really understand what is going on, you must leave a comment on each line of your searching algorithm describing what is happening. Also, as noted above, make sure to include in your comment block, which searching algorithm you are going to implement to search your linked list.
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