-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path14 STL
84 lines (75 loc) · 1.31 KB
/
14 STL
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <list>
#include <map>
using namespace std;
void lists()
{
list<int> lst; // create an empty list
int i;
for(i=0; i<10; i++) lst.push_back(i);
cout << "Size = " << lst.size() << endl;
cout << "Contents: ";
list<int>::iterator p = lst.begin();
while(p != lst.end())
{
cout << *p << " ";
p++;
}
cout << "\n\n";
// change contents of list
p = lst.begin();
while(p != lst.end())
{
*p = *p + 100;
p++;
}
cout << "Contents modified: ";
p = lst.begin();
while(p != lst.end())
{
cout << *p << " ";
p++;
}
cout<<endl;
}
void maps()
{
map<char, int> m;
int i;
// put pairs into map
for(i=0; i<26; i++)
{
m.insert(pair<char, int>('A'+i, 65+i));
}
char ch;
cout << "Enter key: (Use Uppercase) ";
cin >> ch;
map<char, int>::iterator p;
// find value given key
p = m.find(ch);
if(p != m.end())
cout << "Its ASCII value is " << p->second << endl;
else
cout << "Key not in map.\n";
}
int main()
{
int choice;
while(1)
{
cout<<"1. List"<<endl;
cout<<"2. Map"<<endl;
cin>> choice;
switch(choice)
{
case 1:
lists();
break;
case 2:
maps();
break;
default:
exit(0);
}
}
}