Files
hello-algo/ru/codes/cpp/chapter_hashing/hash_map.cpp
Yudong Jin 772183705e Add ru version (#1865)
* Add Russian docs site baseline

* Add Russian localized codebase

* Polish Russian code wording

* Update ru code translation.

* Update code translation and chapter covers.

* Fix pythontutor extraction.

* Add README and landing page.

* placeholder of profiles

* Use figures of English version

* Remove chapter paperbook
2026-03-28 04:24:07 +08:00

47 lines
1.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* File: hash_map.cpp
* Created Time: 2022-12-14
* Author: msk397 (machangxinq@gmail.com)
*/
#include "../utils/common.hpp"
/* Driver Code */
int main() {
/* Инициализация хеш-таблицы */
unordered_map<int, string> map;
/* Операция добавления */
// Добавить пару (key, value) в хеш-таблицу
map[12836] = "Сяо Ха";
map[15937] = "Сяо Ло";
map[16750] = "Сяо Суань";
map[13276] = "Сяо Фа";
map[10583] = "Сяо Я";
cout << "\nПосле добавления хеш-таблица имеет вид\nКлюч -> Значение" << endl;
printHashMap(map);
/* Операция поиска */
// Ввести в хеш-таблицу ключ key и получить значение value
string name = map[15937];
cout << "\nДля студенческого номера 15937 найдено имя " << name << endl;
/* Операция удаления */
// Удалить пару (key, value) из хеш-таблицы
map.erase(10583);
cout << "\nПосле удаления 10583 хеш-таблица имеет вид\nКлюч -> Значение" << endl;
printHashMap(map);
/* Обход хеш-таблицы */
cout << "\nОтдельный обход пар ключ-значение" << endl;
for (auto kv : map) {
cout << kv.first << " -> " << kv.second << endl;
}
cout << "\nОбход пар Key->Value с помощью итератора" << endl;
for (auto iter = map.begin(); iter != map.end(); iter++) {
cout << iter->first << "->" << iter->second << endl;
}
return 0;
}