Key만 저장된다.
중복되지 않는다.
(이진 탐색 트리) 정렬된다.
#include <set>
int main()
{
std::set<int> set;
set.insert(20);
for (std::set<int>::iterator it = set.begin(); it != set.end(); ++it)
{
std::cout << *it << std;;endl;
}
}
-> (key, value) -> (key) 차이 외 map과 같다. (이하 생략)
#include <queue>
int main()
{
// 생성
std::queue<int> q;
std::queue<std::string> q;
std::queue<MyClass> q;
// 삽입
q.push(123);
q.push(MyClass("x", 123));
q.pop(); // 삭제
q.front(); // 가장 처음 들어온 요소
q.back(); // 가장 마지막 들어온 요소
q.size(); // 요소 수
q.empty(); // 비어있는 가?
}
#include <stack>
int main()
{
// 생성
std::stack<int> st;
std::stack<std::string> st;
std::stack<MyClass> st;
// 삽입
st.push(123);
st.push(MyClass("x", 123));
st.pop(); // 삭제
st.top(); // top 반환
st.size(); // 요소 수
st.empty(); // 비어있는 가?
}
앞뒤 요소가 포인터로 연결된 자료구조.
보통 Vector를 대신 쓴다.
#include <list>
int main()
{
std:list<int> l;
l.push_front(1); // 앞에 삽입
l.push_back(2); // 뒤에 삽입
l.insert(iterator, 3); // iterator 위치에 삽입
l.erase(iterator); // iterator 위치 제거
l.remove(value); // value인 요소 다 제거
// 기타 메소드 많음. 생략.
// 참고 : https://en.cppreference.com/w/cpp/container/list
return 0;
}
삽입/제거 O(1)
어느 위치든 삽입/제거 가능
탐색이 느리다.
임의 접근 불가
메모리 불연속적 (* 이것 때문에 vector를 더 선호)
중복 키 허용
요소 수정하면 안됨
중복 키 허용
Double-ended queue
양쪽에서 삽입 삭제 가능
queue에 우선순위 값을 넣을 수 있다.
자동 정렬된다.