


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



// Sequential.h #ifndef SEQUENTIAL_H #define SEQUENTIAL_H const int SIZE = 10; class Sequential { public: int locationWanted; int array[SIZE]; bool SequentialSearch(int[], int, int, int&); }; #endif // Sequential.cpp #include
cout << "The Data\n"; for (i = 0; i < SIZE; i++) SS.array[i] = rand() % 500 + 1; for (i = 0; i < SIZE; i++) cout << SS.array[i] << " "; cout << endl; cout << "Insert a target, or 0 to stop: "; cin >> target; do { found = SS.SequentialSearch(SS.array, SIZE, target, SS.locationWanted); if (found) cout << "\tFound " << target << " at index " << SS.locationWanted << endl; else cout << "\tTarget not found" << endl; cout << "\nInsert a target, or 0 to stop: "; cin >> target; } while (target != 0); } OUTPUT:
bool found; Binary BS; cout << "The Data\n"; /generate an ordered random number list/ BS.array[0] = 1; no = rand() % 500 + 1; while (i < SIZE) { if (no >= BS.array[i - 1]) { BS.array[i] = no; i++; } no = rand() % 500 + 1; } for (i = 0; i < SIZE; i++) cout << BS.array[i] << " "; cout << endl; cout << "Insert a target, or 0 to stop: "; cin >> target; do { found = BS.BinarySearch(BS.array, SIZE, target, BS.locationWanted); if (found) cout << "\n\tFound " << target << " at index " << BS.locationWanted << endl; else cout << "\n\tTarget not found" << endl; cout << "\nInsert a target, or 0 to stop: "; cin >> target; } while (target != 0); } OUTPUT: