Xesh jadvallar orqali ma'lumotlar bazasida nom bo'yicha qidirish
Download 152.33 Kb.
|
4-tajriba ishi
Topshiriq Xesh jadvallar orqali ma'lumotlar bazasida nom bo'yicha qidirish. #include using namespace std; struct Player{ char *ism; int yoshi; int telefon_raqami; Player *next; Player *next_hash; }; int func_hash(Player *q) { int hash = 0; for (size_t i = 0; i { hash += int(q->ism[i]); } return hash%10; } int func_hash_name(char *search_name) { int search_hash = 0; for (size_t i = 0; i {
search_hash += int(search_name[i]); return search_hash%10; } Player *func(Player *p, Player *last, Player *mass[], Player *last_hash) { int action = 0; do {
cin >> action; if (action == 1) { int hash; cout << "Kiriting: ism, yoshi, telefon raqami " << endl; Player *q = new Player; char *a = new char [15]; cin >> a; q->ism = a; int n;
cin >> n; q->yoshi = n; int m; cin >> m; q->telefon_raqami = m; hash = func_hash(q); q->next = NULL; q->next_hash = NULL; if (p == NULL) { p = last = q; } else
{ last->next = q; last = q; }
{ mass[hash] = last_hash = q; } else if (mass[hash] != NULL) { last_hash->next_hash = q; last_hash = q; } } if (action == 2) { cout << " kim haqida ma'lumot kerak : " ; char *search_name = new char [15]; cin >> search_name; int search_hash = func_hash_name(search_name);
while (current != NULL) { cout << "buyruq bajarildi !" << endl< cout << "yoshi : " << current->yoshi << endl; cout << "telefon raqami : " << current->telefon_raqami << endl; cout << endl; current = current->next_hash; } if (p == NULL) { cout << "Ro'yxatdan topilmadi" << endl; } }
while (action != 3); return p; }
{ Player *p = NULL; Player *last = NULL; Player *last_hash = NULL; const int n = 10; Player *mass [n]; for (int i = 0; i {
mass[i] = NULL; p = func(p, last, mass, last_hash); while (p != NULL) { Player *q = p; p = p->next; delete q; } return 0; } Download 152.33 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling