-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlist.cpp
More file actions
67 lines (50 loc) · 1.64 KB
/
list.cpp
File metadata and controls
67 lines (50 loc) · 1.64 KB
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
#include <iostream>
#include <list>
#include <algorithm>
void PrintStats(std::list<std::pair<unsigned int, unsigned int> > &lst)
{
std::list<std::pair<unsigned int, unsigned int> >::iterator ite = lst.begin();
for (; ite != lst.end() ; ++ite)
{
std::cout << "{"<< ite->first << " , " << ite->second << "}" << "\n";
}
}
int main(int ac, char *av[])
{
std::list<std::pair<unsigned int, unsigned int> > lst;
for (int i = 1; i < ac ; i+=2)
{
if (isdigit(*av[i]))
lst.push_back(std::make_pair(std::atoi(av[i]), std::atoi(av[i + 1])));
}
PrintStats(lst);
std::list<std::pair<unsigned int, unsigned int> >::iterator ite = lst.begin();
std::cout << "\n******\n";
for (; ite != lst.end() ; ++ite)
{
if (ite->first > ite->second)
std::swap(ite->first, ite->second);
}
PrintStats(lst);
std::list<unsigned int> lst_a;
ite = lst.begin();
for (; ite != lst.end() ; ++ite)
lst_a.push_back(ite->first);
std::list<unsigned int> lst_b;
ite = lst.begin();
for (; ite != lst.end() ; ++ite)
lst_b.push_back(ite->second);
lst_a.sort();
std::list<unsigned int>::iterator itb = lst_b.begin();
for (; ite != lst_b.end() ; ++ite)
lst_a.push_back(ite->first);
}
// LIST
// std::list<std::pair<unsigned int, unsigned int> > lst;
// for (int i = 1; i < ac; i+=2)
// {
// if (isdigit(*av[i]))
// lst.push_back(std::make_pair(std::atoi(av[i]), std::atoi(av[i + 1])));
// }
// std::list<unsigned int> lst_a, lst_b;
// algo(ac, av, lst, lst_a, lst_b);