#include <iostream>
#include <list>
using namespace std;
/*
리스트의 특징
1. 저장한 데이터의 순서를 보장
2. 중복된 데이터도 삽입 가능
*/
int main(void)
{
//리스트 선언
list<int> lst;
//데이터 추가
lst.push_back(1);lst.push_back(2);
lst.push_back(3);lst.push_back(4);
lst.push_back(5);lst.push_front(6);
lst.push_front(1);lst.push_front(3);
//리스트에 저장된 값의 개수 확인
cout << "저장된 개수 : " << lst.size() << endl;
//lst.clear();//리스트에 내용 비우기
//리스트가 비어있냐? 비어있으면 true, 값이 있으면 false
cout << "리스트가 비었냐? " << lst.empty() << endl;
//리스트에 저장된 모든 3을 삭제
lst.remove(3);
//조회
list<int>::iterator it;
for(it=lst.begin();it!=lst.end();it++)
cout << *it << " ";
cout << endl;
return 0;
}
'Code Archive > C++' 카테고리의 다른 글
| STL. Set 로또 예제 (0) | 2018.02.01 |
|---|---|
| STL. Set 기본 예제 (0) | 2018.02.01 |
| Step6. 생성자와 소멸자 (0) | 2018.01.24 |
| Step5. class 작성 (0) | 2018.01.23 |
| Step Ex. visual studio 2017 C++ 프로젝트 생성 (0) | 2018.01.22 |