Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a sequential search algorithm: Complete the function below by writing the body: public static int search(String[] list, String key) { } This function takes

Implement a sequential search algorithm: Complete the function below by writing the body:

public static int search(String[] list, String key) {

}

This function takes two arguments: an array of strings as the list to search in and a string as the key to search for in the array. The function should perform a sequential search in the array and return the index if the key is found and return -1 otherwise.

NOTE: Strings are objects, not primitive types. For object reference variables, == only tells you whether two reference variables have the same values (meaning they contain the address of the same object, meaning they are pointing to the same object). To check whether two reference variables are pointing to objects with equal values, you need to use .equals.

For testing whether your function is working properly, write a main function where you create an array of strings and call the search function. What else you do in the main function is totally up to you. You do not need to submit the main function.

After you have written the body of the search function and tested it by running the main function, copy and paste the code of the search function.

Please help with this question.

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

Step: 3

blur-text-image

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

Write formal and informal proposals.

Answered: 1 week ago

Question

Describe the components of a formal report.

Answered: 1 week ago

Question

Write formal and informal reports.

Answered: 1 week ago