Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code has errors and i need help fixing it. Preferably in the next 30 minutes if possible. Hers's the question and code Question: the

My code has errors and i need help fixing it. Preferably in the next 30 minutes if possible. Hers's the question and code

Question:

the sequential search algorithm as given in this chapter does not assume that the list is in order. therefore, it usually works the same for both sorted and unsorted lists. however, if the elements of the list are sorted, you can somewhat improve the performance of the sequential search algorithm. for example, if the search item is not in the list, you can stop the search as soon as you find an element in the list that is larger than the search item. write the function seqordsearch to implement a version of the sequential search algorithm for sorted lists. add this function to the class orderedarraylisttype and write a program to test it.

//Header file section #include #include using namespace std;

class orderedArrayListType { //Variable declaration int a[100], i, n; public: //The following function to read the sorted array elements //Function definition void read() { /*Prompt the user to enter an input value*/ cout << "Enter the length of the array: " << endl; cin >> n; cout << "Enter the array elements in ascending order: " << endl; for (i = 0;i> a[i]; }

} void seqOrdSearch() { int j; cout << "Enter the element you want to search: " << endl; cin >> j; for (i = 0; i < n; i++) { if (a[i] > j); { /*When element in the list is greater than the search element it displays that the search item is not found*/ cout << break; } if (a[i] == j) { cout < index:"< break; } }

}

}; void main() { orderedArrayListType s; s.read(); s.seqOrdSearch();

}

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions