-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_list.cpp
77 lines (63 loc) · 1.22 KB
/
test_list.cpp
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
#include <iostream>
#include <string>
using namespace std;
#define USE_STL
#ifndef USE_STL
#include "list.h"
#else
#include <list>
#endif
template <typename T>
void print(list<T>& l){
#ifndef USE_STL
typename list<T>::Iter iter = l.begin();
typename list<T>::Iter e = l.end();
#else
typename list<T>::iterator iter = l.begin();
typename list<T>::iterator e = l.end();
#endif
while(iter != e){
cout<< *iter << endl;
iter++;
}
}
class Test
{
public:
static int i;
Test(){
cout << "construct..."<<endl;
}
Test(const Test& t){
*this = t;
cout << "copy construct..." << endl;
}
~Test(){
i++;
cout << "deconstruct..."<<endl;
}
};
int Test::i = 0;
int main() {
list<int> l;
l.push_back(1);
l.push_back(2);
l.push_front(3);
l.push_front(4);
print(l);
l.pop_back();
l.pop_front();
print(l);
list<int>::iterator loc = l.end();
l.insert(loc,33);
cout << "---------------"<<endl;
print(l);
Test t1;
list<Test> ll;
ll.push_back(t1);
list<string> ls;
ls.push_back(string("sdfsd"));
ls.push_back(string("sdfsdf"));
ls.push_back(string("sdfsdsdsd"));
print(ls);
}