Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Searching()
- {
- FILE* f;
- air a1;
- char filename[81],place[81];
- int choice, cnt = 0, g = 0;
- cout << "Введите имя файла" << endl;
- cin.ignore();
- cin.getline(filename, 81);
- f = fopen(filename, "r+");
- if (f == NULL)
- {
- cout << "Данного файла не существует" << endl;
- return;
- }
- fseek(f, 0, SEEK_SET);
- int size = _filelength(_fileno(f));
- size /= sizeof(air);
- cout << "Введите ключ" << endl;
- cin.getline(place, 81);
- cin.ignore();
- air temp;
- for (int i = 0; i < size; i++)
- {
- fread(&temp, sizeof(air), 1, f);
- if (strcmp(temp.area, place) == 0) cnt++;
- }
- air* array = new air[cnt];
- fseek(f, 0, SEEK_SET);
- for (int i = 0; i < size; i++)
- {
- fread(&temp, sizeof(air), 1, f);
- if (strcmp(temp.area, place) == 0) array[g++] = temp;
- }
- cout << "1.Линейный поиск" << "\n2.Бинарный поиск" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:
- {
- int i_key = 0, kod = 0;
- for (int i = 0; i < size; i++)
- if (array[i].area == place)
- {
- kod = 1;
- i_key = i;
- cout << "Интересуемый Вас элемент расположен в ячейке под номером: " << i_key << endl;
- return;
- }
- if (kod == 0)
- cout << "По вашему запросу ничего не найдено" << endl;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement