◎ 삽입, 삭제
- 삽입,삭제 함수 벡터와 동일
iterator insert(iterator it, const T& x = T());
void insert(iterator it, size_type n, const T& x);
void insert(iterator it, const_iterator first, const_iterator last);
iterator erase(iterator it);
iterator erase(iterator first, iterator last);
- list 예)
1 #include <iostream>
2 #include <list>
3
4 using namespace std;
5
6 template <typename C>
7 void dump(const char *desc, C c) 8 {
9 cout.width(12);
10 cout << left << desc << "==> " ;
11 copy(c.begin(), c.end(), ostream_iterator<typename C::value_type>(cout," "));
12 cout << endl;
13 }
14
15 void main()
16 {
17 const char *str = "abcedfghij";
18 list<char>lc(&str[0], &str[10]);
19 list<char>::iterator it;
20
21 dump("최초", lc);
22 it = lc.begin();
23 it++;
24 it++;
25 it++;
26 it++;
27
28 lc.insert(it, 'Z');
29 dump("Z 삽입", lc);
30
31 it = lc.end();
32 it--;
33 it--;
34 it--;
35 lc.erase(it);
36 dump("h 삭제",lc);
37 }
1 #include <iostream>
2 #include <list>
3
4 using namespace std;
5
6 template<typename C> void dump(const char *desc, C c) { cout.width(12);cout << left << desc << "==> ";
7 copy(c.begin(),c.end(),ostream_iterator<typename C::value_type>(cout," ")); cout << endl; }
8
9 void main()
10 {
11 const char *str="double linked list class";
12 list<char> li(&str[0],&str[strlen(str)]);
13
14 dump("최초",li);
15 li.remove('l');
16 dump("l삭제",li);
17 }
ps : 출처 및 자세한 내용은 www.WinAPI.co.kr 참고
'[ C/ C++ 프로그래밍 ] > [ STL ]' 카테고리의 다른 글
[ 혼연 정리 ] 시퀀스 컨테이너 - 9 [ 리스트 ] (0) | 2010.06.24 |
---|---|
[ 혼연 정리 ] 시퀀스 컨테이너 - 8 [ 리스트 ] (2) | 2010.06.24 |
[ 혼연 정리 ] 시퀀스 컨테이너- 6 [ 리스트 ] (0) | 2010.06.24 |
[ 혼연 정리 ] 시퀀스 컨테이너 - 5 [ 벡터 ] (1) | 2010.06.24 |
[ 혼연 정리 ] 시퀀스 컨테이너 - 4 [ 벡터 ] (0) | 2010.06.24 |