{"id":1474,"date":"2014-08-08T04:52:04","date_gmt":"2014-08-07T21:52:04","guid":{"rendered":"http:\/\/www.itersdesktop.com\/?p=1474"},"modified":"2017-01-25T01:35:20","modified_gmt":"2017-01-24T23:35:20","slug":"lam-the-nao-de-tao-mot-danh-sach-voi-chi-muc-kieu-chuoi-tren-c","status":"publish","type":"post","link":"https:\/\/www.itersdesktop.com\/vi\/2014\/08\/08\/lam-the-nao-de-tao-mot-danh-sach-voi-chi-muc-kieu-chuoi-tren-c\/","title":{"rendered":"L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 t\u1ea1o m\u1ed9t danh s\u00e1ch v\u1edbi ch\u1ec9 m\u1ee5c ki\u1ec3u chu\u1ed7i tr\u00ean C++"},"content":{"rendered":"<p><\/p>\n<div style=\"font-style: italic; text-align: justify;\">Trong m\u1ed9t b\u00e0i vi\u1ebft tr\u01b0\u1edbc, t\u00f4i c\u00f3 gi\u1edbi thi\u1ec7u v\u1edbi c\u00e1c b\u1ea1n <a title=\"Array, List, etc. v\u1edbi ch\u1ec9 m\u1ee5c l\u00e0 chu\u1ed7i\" href=\"http:\/\/www.itersdesktop.com\/2013\/12\/17\/array-list-etc-voi-chi-muc-la-chuoi\/\" target=\"_blank\">t\u1ea1o danh s\u00e1ch\/m\u1ea3ng v\u1edbi c\u00e1ch \u0111\u00e1nh ch\u1ec9 m\u1ee5c b\u1eb1ng chu\u1ed7i k\u00ed t\u1ef1 trong l\u1eadp tr\u00ecnh Python<\/a>. \u00a0B\u00e0i vi\u1ebft n\u00e0y s\u1ebd gi\u1edbi thi\u1ec7u m\u1ee5c \u0111\u00edch t\u01b0\u01a1ng t\u1ef1 nh\u01b0ng l\u1eadp tr\u00ecnh trong ng\u00f4n ng\u1eef C++. K\u0129 thu\u1eadt ch\u00ednh l\u00e0 d\u00f9ng l\u1edbp <a title=\"Map class\" href=\"http:\/\/www.cplusplus.com\/reference\/map\/map\/\" target=\"_blank\">map<\/a>.<\/div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a150791a7328\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a150791a7328\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.itersdesktop.com\/vi\/2014\/08\/08\/lam-the-nao-de-tao-mot-danh-sach-voi-chi-muc-kieu-chuoi-tren-c\/#gioi-thieu-so-ve-lop-map\" >Gi\u1edbi thi\u1ec7u s\u01a1 v\u1ec1 l\u1edbp map<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.itersdesktop.com\/vi\/2014\/08\/08\/lam-the-nao-de-tao-mot-danh-sach-voi-chi-muc-kieu-chuoi-tren-c\/#cai-dat-associative-array-su-dung-map\" >C\u00e0i \u0111\u1eb7t associative array s\u1eed d\u1ee5ng map<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.itersdesktop.com\/vi\/2014\/08\/08\/lam-the-nao-de-tao-mot-danh-sach-voi-chi-muc-kieu-chuoi-tren-c\/#mot-so-cach-khac\" >M\u1ed9t s\u1ed1 c\u00e1ch kh\u00e1c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.itersdesktop.com\/vi\/2014\/08\/08\/lam-the-nao-de-tao-mot-danh-sach-voi-chi-muc-kieu-chuoi-tren-c\/#tham-khao\" >Tham kh\u1ea3o<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.itersdesktop.com\/vi\/2014\/08\/08\/lam-the-nao-de-tao-mot-danh-sach-voi-chi-muc-kieu-chuoi-tren-c\/#overview-of-map-stl\" >Overview of map STL<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"gioi-thieu-so-ve-lop-map\"><\/span><span style=\"color: #008080; font-weight: bold;\">Gi\u1edbi thi\u1ec7u s\u01a1 v\u1ec1 l\u1edbp map<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div style=\"text-align: justify;\"><a title=\"Map\" href=\"http:\/\/www.cplusplus.com\/reference\/map\/map\/\" target=\"_blank\">Map<\/a> l\u00e0 m\u1ed9t trong nh\u1eefng ki\u1ec3u d\u1eef li\u1ec7u b\u00ecnh ch\u1ee9a k\u1ebft h\u1ee3p (asssociative container): ngh\u0129a l\u00e0 m\u1ed7i ph\u1ea7n t\u1eed trong b\u00ecnh ch\u1ee9a l\u00e0 m\u1ed9t s\u1ef1 k\u1ebft h\u1ee3p gi\u1eefa gi\u00e1 tr\u1ecb kh\u00f3a (key value) v\u00e0 gi\u00e1 tr\u1ecb t\u01b0\u01a1ng \u1ee9ng v\u1edbi kh\u00f3a \u0111\u00f3 (mapped value). Map l\u00e0 m\u1ed9t l\u1edbp trong b\u1ed9 nh\u00f3m c\u00e1c ki\u1ec3u d\u1eef li\u1ec7u t\u1eadp h\u1ee3p (containers) \u0111\u01b0\u1ee3c c\u00e0i \u0111\u1eb7t trong b\u1ed9 th\u01b0 vi\u1ec7n m\u1eabu chu\u1ea9n <a title=\"Standard Template Libraries\" href=\"http:\/\/www.sgi.com\/tech\/stl\/\" target=\"_blank\">STL<\/a> c\u1ee7a ng\u00f4n ng\u1eef C++.<\/div>\n<div>C\u00e1c gi\u00e1 tr\u1ecb kh\u00f3a l\u00e0 d\u1eef li\u1ec7u thu\u1ed9c ki\u1ec3u t\u00f9y \u00fd. V\u00e0 do \u0111\u00f3, ch\u00fang ta c\u00f3 th\u1ec3 d\u00f9ng c\u00e1c chu\u1ed7i k\u00ed t\u1ef1 l\u00e0m key value cho m\u1ed9t map.<\/div>\n<div>\n<figure id=\"attachment_1661\" aria-describedby=\"caption-attachment-1661\" style=\"width: 416px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1661 size-full\" src=\"http:\/\/www.itersdesktop.com\/wp-content\/uploads\/2014\/08\/associativearray.png\" alt=\"Associative Array\" width=\"416\" height=\"147\" srcset=\"https:\/\/www.itersdesktop.com\/wp-content\/uploads\/2014\/08\/associativearray.png 416w, https:\/\/www.itersdesktop.com\/wp-content\/uploads\/2014\/08\/associativearray-300x106.png 300w\" sizes=\"auto, (max-width: 416px) 100vw, 416px\" \/><figcaption id=\"caption-attachment-1661\" class=\"wp-caption-text\">Associative Array<\/figcaption><\/figure>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"cai-dat-associative-array-su-dung-map\"><\/span><span style=\"color: #008080; font-weight: bold;\">C\u00e0i \u0111\u1eb7t associative array s\u1eed d\u1ee5ng map<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div>\n<pre class=\"decode-attributes:true lang:c++ decode:true\">#include\r\n\r\n\r\n\r\n<map>\r\nusing namespace std;\r\nstd::map &lt;string, char&gt; ranks;\r\nranks[\"Tung\"] = 'A';\r\nranks[\"Cuc\"] = 'A';\r\nranks[\"Truc\"] = 'C';\r\nranks[\"Mai\"] = 'B';\r\n\/\/ Tra ve \"Tung\"\r\nstd::cout&lt;&lt;ranks.begin()-&gt;first&lt;&lt;endl;\r\n\/\/ Tra v\u1ec1'A'\r\nstd::cout&lt;&lt;ranks.begin()-&gt;second&lt;&lt;endl;\r\n<\/map><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"mot-so-cach-khac\"><\/span><span style=\"color: #008080; font-weight: bold;\">M\u1ed9t s\u1ed1 c\u00e1ch kh\u00e1c<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div>HashTable (c\u0169ng c\u00f3 t\u00ean g\u1ecdi kh\u00e1c l\u00e0 HashMap) l\u00e0 m\u1ed9t ki\u1ec3u d\u1eef li\u1ec7u th\u00f9ng ch\u1ee9a k\u1ebft h\u1ee3p t\u1ed5ng qu\u00e1t (Associative Array) d\u00f9ng \u0111\u1ec3 l\u01b0u tr\u1eef c\u00e1c ph\u1ea7n t\u1eed c\u00f3 c\u1ea5u tr\u00fac: m\u1ed9t kh\u00f3a duy nh\u1ea5t (key) k\u1ebft h\u1ee3p v\u1edbi m\u1ed9t gi\u00e1 tr\u1ecb (value). STL kh\u00f4ng c\u00e0i \u0111\u1eb7t\u00a0HashMap. V\u00ec v\u1eady, \u0111\u1ed1i v\u1edbi ng\u01b0\u1eddi l\u1eadp tr\u00ecnh c\u00f3 th\u1ec3 t\u1ef1 x\u00e2y d\u1ef1ng m\u1ed9t l\u1edbp HashMap ph\u00f9 h\u1ee3p v\u1edbi nhu c\u1ea7u c\u00f4ng vi\u1ec7c c\u1ee7a m\u00ecnh.<\/div>\n<div><\/div>\n<div>Trong JavaScript, \u0111\u1ec3 t\u1ea1o m\u1ed9t associative array th\u1eadt \u0111\u01a1n gi\u1ea3n. Xin tham kh\u1ea3o th\u00eam m\u1ed9t b\u00e0i vi\u1ebft b\u00ean ngo\u00e0i <a href=\"http:\/\/debugmode.net\/2012\/11\/13\/what-is-associative-array-in-javascript\/\" target=\"_blank\">What is associative array in JavaScript<\/a>.<\/div>\n<div><\/div>\n<h3><span class=\"ez-toc-section\" id=\"tham-khao\"><\/span><span style=\"color: #008080; font-weight: bold;\">Tham kh\u1ea3o<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div><a href=\"http:\/\/www.cplusplus.com\/reference\/map\/map\/\">Map in C++<\/a><\/div>\n<div><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/xfhwa508.aspx\" target=\"_blank\">N\u00f3i th\u00eam v\u00e0 ki\u1ec3u d\u1eef li\u1ec7u t\u1eeb \u0111i\u1ec3n\u00a0trong C#<\/a><\/div>\n<div><a href=\"http:\/\/stackoverflow.com\/a\/416249\">C\u00f3 m\u1ed9t gi\u1ea3i ph\u00e1p kh\u00e1c d\u00f9ng enum<\/a><\/div>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Trong m\u1ed9t b\u00e0i vi\u1ebft tr\u01b0\u1edbc, t\u00f4i c\u00f3 gi\u1edbi thi\u1ec7u v\u1edbi c\u00e1c b\u1ea1n t\u1ea1o danh s\u00e1ch\/m\u1ea3ng v\u1edbi c\u00e1ch \u0111\u00e1nh ch\u1ec9 m\u1ee5c b\u1eb1ng chu\u1ed7i k\u00ed t\u1ef1 trong l\u1eadp tr\u00ecnh Python. \u00a0B\u00e0i vi\u1ebft&hellip; <\/p>\n","protected":false},"author":2,"featured_media":1661,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,348,230],"tags":[483,484,482],"class_list":["post-1474","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpp","category-data-structures","category-programming","tag-associative-array","tag-associative-container","tag-string-index"],"_links":{"self":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts\/1474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/comments?post=1474"}],"version-history":[{"count":40,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts\/1474\/revisions"}],"predecessor-version":[{"id":2580,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts\/1474\/revisions\/2580"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/media\/1661"}],"wp:attachment":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/media?parent=1474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/categories?post=1474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/tags?post=1474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}