Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include //Write a binary and linear search for the following program to work in

ID: 3530099 • Letter: #

Question

#include //Write a binary and linear search for the following program to work in visual studio. #include#include #includeusing namespace std; int main() { int option; int currentList[50]; bool ordered = false; int length = 0; int input; int max; int min; int binarySearch(int currentList[], int value, int left, int right); for(int i = 0; i < 50; i++) { currentList[i] = -1; } cout << "(empty)" << endl; cout << "not known to be ordered" << endl; cout << "1. Reset the current list from the keyboard" << endl; cout << "2. Reset the current list using randomly generated elements" << endl; cout << "3. Perform Bubble Sort on the current list" << endl; cout << "4. Perform Insertion Sort on the current list" << endl; cout << "5. Perform Selection Sort on the current list" << endl; cout << "6. Perform Linear Search on the current list" << endl; cout << "7. Perform Binary Search on the current list" << endl; cout << "8. Quit the program" << endl; cin >> option; while(option != 8) { if(option == 1) { length = 0; cout << "Enter values to put into current list, enter -1 to stop" << endl; cin >> input; while(input != -1 && length < 50) { if(input < 0) { cout << "Must enter positive value" << endl; } else { currentList[length] = input; length = length + 1; } cin >> input; } } if(option == 2) { cout << "Enter the amount of elements you want in the list." << endl; cin >> length; cout << "Enter the maximum amount of elements you want in the list." << endl; cin >> max; cout << "Enter the minimum amount of elements you want in the list." << endl; cin >> min; for(int i=0;i<50;i++) { if(i< length - j; i++) { if (currentList[i] > currentList[i + 1]) { tmp = currentList[i]; currentList[i] = currentList[i + 1]; currentList[i + 1] = tmp; swapped = true; } } } } if(option == 4) { int i, j, tmp; for (i = 1; i < length; i++) { j = i; while (j > 0 && currentList[j - 1] > currentList[j]) { tmp = currentList[j]; currentList[j] = currentList[j - 1]; currentList[j - 1] = tmp; j--; } } } if(option == 5) { int i, j, minIndex, tmp; for (i = 0; i < length - 1; i++) { minIndex = i; for (j = i + 1; j < length; j++) if (currentList[j] < currentList[minIndex]) minIndex = j; if (minIndex != i) { tmp = currentList[i]; currentList[i] = currentList[minIndex]; currentList[minIndex] = tmp; } } } if(option == 6) { } if(option == 7) { } if(length == 0) { cout << "(empty)" << endl; } else { for(int i = 0; i < length; i++) { cout << i << ": " << currentList[i] << endl; } } if(ordered == true) { cout << "known to be ordered" << endl; } else { cout << "not known to be ordered" << endl; } cout << "1. Reset the current list from the keyboard" << endl; cout << "2. Reset the current list using randomly generated elements" << endl; cout << "3. Perform Bubble Sort on the current list" << endl; cout << "4. Perform Insertion Sort on the current list" << endl; cout << "5. Perform Selection Sort on the current list" << endl; cout << "6. Perform Linear Search on the current list" << endl; cout << "7. Perform Binary Search on the current list" << endl; cout << "8. Quit the program" << endl; cin >> option; } return 0; }

Explanation / Answer

i am giving you the logic


for binary