### binary search and sequential search algorithm

Write a program to find the number of comparisons using the binary search and sequential search algorithms
 ``12345678910111213`` ``````//main.cpp #include #include #include "orderedArrayListType.h" using namespace std; int main() { cout << "." << endl; return 0; } ``````

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293`` ``````//arraylisttype.h #ifndef H_arrayListType #define H_arrayListType #include #include using namespace std; template class arrayListType { public: const arrayListType& operator= (const arrayListType&); //Overloads the assignment operator bool isEmpty() const; //Function to determine whether the list is empty //Postcondition: Returns true if the list is empty; // otherwise, returns false. bool isFull() const; //Function to determine whether the list is full. //Postcondition: Returns true if the list is full; // otherwise, returns false. int listSize() const; int maxListSize() const; void print() const; bool isItemAtEqual(int location, const elemType& item) const; void insertAt(int location, const elemType& insertItem); void insertEnd(const elemType& insertItem); void removeAt(int location); void retrieveAt(int location, elemType& retItem) const; void replaceAt(int location, const elemType& repItem); void clearList(); int seqSearch(const elemType& item) const; void insert(const elemType& insertItem); void remove(const elemType& removeItem); arrayListType(int size = 100); arrayListType(const arrayListType& otherList); ~arrayListType(); protected: elemType *list; int length; int maxSize; }; template bool arrayListType::isEmpty() const { return (length == 0); } template bool arrayListType::isFull() const { return (length == maxSize); } template int arrayListType::listSize() const { return length; } template int arrayListType::maxListSize() const { return maxSize; } template void arrayListType::print() const { for (int i = 0; i < length; i++) cout << list[i] << " "; cout << endl; } template bool arrayListType::isItemAtEqual (int location, const elemType& item) const { return(list[location] == item); } template void arrayListType::insertAt (int location, const elemType& insertItem) { if (location < 0 || location >= maxSize) cerr << "The position of the item to be inserted " << "is out of range" << endl; else if (length >= maxSize) //list is full cerr << "Cannot insert in a full list" << endl; else { for (int i = length; i > location; i--) list[i] = list[i - 1]; //move the elements down list[location] = insertItem; //insert the item at the //specified position length++; //increment the length } } //end insertAt template void arrayListType::insertEnd(const elemType& insertItem) { if (length >= maxSize) //the list is full cerr << "Cannot insert in a full list" << endl; else { list[length] = insertItem; //insert the item at the end length++; //increment the length } } //end insertEnd template void arrayListType::removeAt(int location) { if (location < 0 || location >= length) cerr << "The location of the item to be removed " << "is out of range" << endl; else { for (int i = location; i < length - 1; i++) list[i] = list[i+1]; length--; } } //end removeAt template void arrayListType::retrieveAt (int location, elemType& retItem) const { if (location < 0 || location >= length) cerr << "The location of the item to be retrieved is " << "out of range." << endl; else retItem = list[location]; } //end retrieveAt template void arrayListType::replaceAt (int location, const elemType& repItem) { if (location < 0 || location >= length) cerr << "The location of the item to be replaced is " << "out of range." << endl; else list[location] = repItem; } //end replaceAt template void arrayListType::clearList() { length = 0; } //end clearList template int arrayListType::seqSearch(const elemType& item) const { int loc; bool found = false; for (loc = 0; loc < length; loc++) if (list[loc] == item) { found = true; break; } if (found) return loc; else return -1; } //end seqSearch template void arrayListType::insert(const elemType& insertItem) { int loc; if (length == 0) //list is empty list[length++] = insertItem; //insert the item and //increment the length else if (length == maxSize) cerr << "Cannot insert in a full list." << endl; else { loc = seqSearch(insertItem); if (loc == -1) //the item to be inserted //does not exist in the list list[length++] = insertItem; else cerr << "the item to be inserted is already in " << "the list. No duplicates are allowed." << endl; } } //end insert template void arrayListType::remove(const elemType& removeItem) { int loc; if (length == 0) cerr << "Cannot delete from an empty list." << endl; else { loc = seqSearch(removeItem); if (loc != -1) removeAt(loc); else cout << "The item to be deleted is not in the list." << endl; } } //end remove template arrayListType::arrayListType(int size) { int maxSize; if (size < 0) { cerr << "The array size must be positive. Creating " << "an array of size 100. " << endl; maxSize = 100; } else maxSize = size; length = 0; list = new elemType[maxSize]; assert(list != NULL); } template arrayListType::~arrayListType() { delete [] list; } template arrayListType::arrayListType (const arrayListType& otherList) { maxSize = otherList.maxSize; length = otherList.length; list = new elemType[maxSize]; assert(list != NULL); //memory space for (int j = 0; j < length; j++) list [j] = otherList.list[j]; } //end copy constructor template const arrayListType& arrayListType::operator= (const arrayListType& otherList) { if (this != &otherList) { delete [] list; maxSize = otherList.maxSize; length = otherList.length; list = new elemType[maxSize]; assert(list != NULL); //space, terminate the program for (int i = 0; i < length; i++) list[i] = otherList.list[i]; } return *this; } #endif ``````

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105`` ``````//orderedarraylist.h //orderedArrayListType// #ifndef H_OrderedListType #define H_OrderedListType #include #include "arrayListType.h" using namespace std; double list; int length; int maxSize; template class orderedArrayListType: public arrayListType { public: void insertOrd(const elemType&); int binarySearch(const elemType& item) const; orderedArrayListType(int size = 100); }; template void orderedArrayListType::insertOrd(const elemType& item) { double list; int length; int first = 0; int last = length - 1; int mid; int maxSize; bool found = false; if (length == 0) { list[0] = item; length++; } else if (length == maxSize) cerr << "Cannot insert into a full list." << endl; else { while (first <= last && !found) { mid = (first + last) / 2; if (list[mid] == item) found = true; else if (list[mid] > item) last = mid - 1; else first = mid + 1; }//end while if (found) cerr << "The insert item is already in the list. " << "Duplicates are not allowed." << endl; else { if (list[mid] < item) mid++; insertAt(mid, item); } } }//end insertOrd template int orderedArrayListType::binarySearch (const elemType& item) const { int first = 0; int last = length - 1; int mid; bool found = false; while (first <= last && !found) { mid = (first + last) / 2; if (list[mid] == item) found = true; else if (list[mid] > item) last = mid - 1; else first = mid + 1; } if (found) return mid; else return -1; }//end binarySearch template orderedArrayListType::orderedArrayListType(int size) : arrayListType(size) { } #endif ``````

 Write a program to find the number of comparisons using the binary search and sequential search algorithms
Are you expected to write your own containers?

If not, you can use standard containers that are linear and binary searches (like vector and set), then pass in your own comparison thing with a counter on it, then display the counter.

It'll be much simpler.
this is the full questions for the above pre-solution
 Write a program to find the number of comparisons using the binary search and sequential search algorithms as follows: Suppose list is an array of 1000 elements. a. Use a random number generator to fill list. b. Use any sorting algorithm to sort list. Alternatively, you can use the function insertOrd to initially insert all the elements in the list. c. Search the list for some items, as follows: i. Use the binary search algorithm to search the list. (You might need to modify the algorithm to count the number of comparisons.) ii. Use the binary search algorithm to search the list, switching to a sequential search when the size of the search list reduces to less than 15. (Use the sequential search algorithm for a sorted list.) d. Print the number of comparisons for Steps c.i and c.ii. If the item is found in the list, then print its position.
 ``123456`` ``````int main() { cout << "." << endl; return 0; }``````

... cant get an output out of dis code ...