Files
hello-algo/ru/codes/swift/chapter_hashing/hash_map.swift
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

52 lines
1.8 KiB
Swift
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.swift
* Created Time: 2023-01-16
* Author: nuomi1 (nuomi1@qq.com)
*/
import utils
@main
enum HashMap {
/* Driver Code */
static func main() {
/* Инициализация хеш-таблицы */
var map: [Int: String] = [:]
/* Операция добавления */
// Добавить пару (key, value) в хеш-таблицу
map[12836] = "Сяо Ха"
map[15937] = "Сяо Ло"
map[16750] = "Сяо Суань"
map[13276] = "Сяо Фа"
map[10583] = "Сяо Я"
print("\nПосле добавления хеш-таблица имеет вид\nКлюч -> Значение")
PrintUtil.printHashMap(map: map)
/* Операция поиска */
// Ввести в хеш-таблицу ключ key и получить значение value
let name = map[15937]!
print("\nДля номера 15937 найдено имя \(name)")
/* Операция удаления */
// Удалить пару (key, value) из хеш-таблицы
map.removeValue(forKey: 10583)
print("\nПосле удаления 10583 хеш-таблица имеет вид\nКлюч -> Значение")
PrintUtil.printHashMap(map: map)
/* Обход хеш-таблицы */
print("\nОтдельный обход пар ключ-значение")
for (key, value) in map {
print("\(key) -> \(value)")
}
print("\nОтдельный обход ключей")
for key in map.keys {
print(key)
}
print("\nОтдельный обход значений")
for value in map.values {
print(value)
}
}
}