void Camiao::retiraServico(Servico *s1) { int index = sequentialSearch(servicos, s1); if (index == -1) throw ServicoInexistente(s1->getId()); else servicos.erase(servicos.begin() + index); }
bool Reader::removeRequest(Request request) { int index = sequentialSearch(requestedBooks, request); if (index == -1) return false; else requestedBooks.erase(requestedBooks.begin() + index); return true; }
bool Reader::addRequest(Request request) { if (sequentialSearch(requestedBooks, request) != -1) return false; else requestedBooks.push_back(request); lastActivity = request.getDate(); inactive = false; return true; }
int main() { int found = 0; int i = 0; int number; FILE *fp = fopen("input.txt", "r"); /* fp gets the pointer to the file */ //Use this array to store the elements read from output.txt int num[MAX_NUMS]; // Array of MAX_NUMS numbers. Usually dynamic memory is preferred. // But for this lab, array is fine. //Search key int search_key; //Variables for time measurement double ttime; struct timeval start, end; /* * *Code to read numbers from output.txt to the array num * */ while (fscanf(fp, "%d", &number) != EOF && i < MAX_NUMS) { num[i] = number; i++; } fclose(fp); //Do not change this printf("Enter the key to search:\n"); scanf("%d", &search_key); gettimeofday(&start, NULL); //Implement the sequential search algorithm in the sequentialSearch function found = sequentialSearch(num, search_key); gettimeofday(&end, NULL); if (found == 1) printf("Key found\n"); else printf("Key not found\n"); ttime = (double)(end.tv_sec + end.tv_usec/1000000.0) - (start.tv_sec + start.tv_usec/1000000.0); printf ("Time taken (sec): %g\n", ttime); return 0; }
void Search::sequentialSearchEntry(int numArray[], int arraySize) { bool test = true; int startTime = time(NULL); for (int i = 0; i < searchSize; i++) { test = sequentialSearch(numArray, i+1, arraySize); if (test == false) { cout << "Broken: " << i << endl; } } int endTime = time(NULL); int time = difftime(endTime, startTime); cout << "[" << time << "s]\t Sequential Search Completed" << endl; }