1. list ¶
- λ§λ€κΈ° κΉλ€λ‘μ΄ λλΈ λ§ν¬λ 리μ€νΈλ₯Ό μ 곡ν΄μ€λ€.
- include : list
~cpp #include <list>
1.2. λ°μ΄ν° λ£κΈ° ¶
~cpp l.push_back(5); // 맨 λ€μ λ£κΈ° l.push_front(4); // 맨 μμ λ£κΈ°
1.3. μν ¶
~cpp
list<int>::iterator i;
// for μμ λ°λ³΅μ μ΄μ© μν
for(i = l.begin() ; i != l.end() ; ++i)
cout << *i << endl;
// while μμ λ°λ³΅μ μ΄μ©μν
i = l.begin();
while( i != l.end() ){
cout << *i << endl;
i++;
}
1.4. νλ‘κ·Έλ¨μ μ ¶
~cpp
#include <list>
#include <iostream>
using namespace std;
int main(){
const int INDEX_MAX = 5;
int data[] = {1,2,3,4,5};
list<int> l(&data[0], &data[INDEX_MAX]);
list<int>::iterator i ;
cout << "for λ¬Έμμ λ°λ³΅μ μ΄μ© μν" << endl;
for(i = l.begin() ; i != l.end() ; ++i)
cout << *i << "t";
cout << endl;
cout << "while λ¬Έμμ λ°λ³΅μ μ΄μ© μν" << endl;
i = l.begin();
while( i != l.end() ){
cout << *i << "t";
i++;
}
return 0;
}
κ²°κ³Ό
~cpp for λ¬Έμμ λ°λ³΅μ μ΄μ© μν 1 2 3 4 5 while λ¬Έμμ λ°λ³΅μ μ΄μ© μν 1 2 3 4 5
1.5. μΆκ° μ§μ ¶
list μ λ°λ³΅μλ μλ°©ν₯ λ°λ³΅μλ‘μ μμ μ κ·Ό λ°λ³΅μκ° μ§μνλ μ°μ°μ μ μΈν κΈ°ν λͺ¨λ μ°μ°μμ λν μ°μ°μ μ§μνλ€.
AC++ 8μ₯μ μ°Έκ³ νκΈ° λ°λ.
----
STL AcceleratedC++/Chapter8
AC++ 8μ₯μ μ°Έκ³ νκΈ° λ°λ.
STL AcceleratedC++/Chapter8










