Brumski's DSA Learning Project 1.3
For Learning Data Structures and Algorithms in C++
Loading...
Searching...
No Matches
map_dsa.hpp
1#pragma once
2
3#include <map>
4#include <string>
5#include <utility>
6#include <list>
7#include <iostream>
8
9void UsingMap() {
10 std::cout << "\nMAP (1) DATA STRUCTURE" << std::endl;
11
12 std::map<std::string, std::pair<std::string, std::string>> students;
13 students.emplace("7890", std::pair{ "David", "Tamaratare" });
14 students.emplace("7891", std::pair{"David", "Tamaralayefa"});
15 students.emplace("7892", std::pair{"Daniel", "Mark"});
16
17 std::cout << "The student with a MATRIC. NO. of 7890 is " << students["7890"].first << " " << students["7890"].second << std::endl;
18}
19
20void UsingMap2() {
21 std::cout << "\nMAP (2) DATA STRUCTURE" << std::endl;
22
23 std::map<std::string, std::list<std::string>> students;
24 students.emplace("7890", std::list<std::string>{"David", "Tamaratare", "Oghenebrume"});
25 students.emplace("7891", std::list<std::string>{"David", "Tamaralayefa"});
26 students.emplace("7892", std::list<std::string>{"David", "Oghenebrume"});
27
28 for (auto& student : students) {
29 std::cout << "The student with a MATRIC. NO. of " << student.first << " is ";
30 for (auto& name : student.second) {
31 std::cout << name << " ";
32 }
33 std::cout << std::endl;
34 }
35}