-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReversePrint.cpp
More file actions
42 lines (32 loc) · 832 Bytes
/
ReversePrint.cpp
File metadata and controls
42 lines (32 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* \file ReversePrint.cpp
* \brief
*
* \todo
*/
#include <iostream>
#include <map>
#include <string>
#include <iterator>
int main() {
// Creating & Initializing a map of String & Ints
std::map<std::string, int> mapOfWordCount = {
{ "aaa", 10 },
{ "ddd", 11 },
{ "bbb", 12 },
{ "ccc", 13 }
};
// Create a map iterator and point to the end of map
std::map<std::string, int>::reverse_iterator it = mapOfWordCount.rbegin();
// Iterate over the map using Iterator till beginning.
while (it != mapOfWordCount.rend()) {
// Accessing KEY from element pointed by it.
std::string word = it->first;
// Accessing VALUE from element pointed by it.
int count = it->second;
std::cout << word << " :: " << count << std::endl;
// Increment the Iterator to point to next entry
it++;
}
return 0;
}