STL 학습 - Stack / Queue 편
Stack
template <class _Tp, class _Sequence>
class stack {
...
public:
typedef typename _Sequence::value_type value_type;
typedef typename _Sequence::size_type size_type;
typedef _Sequence container_type;
typedef typename _Sequence::reference reference;
typedef typename _Sequence::const_reference const_reference;
protected:
_Sequence c; //
public:
// Squence c , stack
stack() : c() {}
explicit stack(const _Sequence& __s) : c(__s) {}
//
bool empty() const { return c.empty(); }
//
size_type size() const { return c.size(); }
//
reference top() { return c.back(); }
const_reference top() const { return c.back(); }
//
void push(const value_type& __x) { c.push_back(__x); }
//
void pop() { c.pop_back(); }
};
//
template <class _Tp, class _Seq>
bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
{
return __x.c == __y.c;
}
//
template <class _Tp, class _Seq>
bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
{
return __x.c < __y.c;
}
...
Queue
template <class _Tp, class _Sequence>
class queue {
...
public:
typedef typename _Sequence::value_type value_type;
typedef typename _Sequence::size_type size_type;
typedef _Sequence container_type;
typedef typename _Sequence::reference reference;
typedef typename _Sequence::const_reference const_reference;
protected:
_Sequence c; //
public:
queue() : c() {}
explicit queue(const _Sequence& __c) : c(__c) {}
//
bool empty() const { return c.empty(); }
//
size_type size() const { return c.size(); }
//
reference front() { return c.front(); }
const_reference front() const { return c.front(); }
//
reference back() { return c.back(); }
const_reference back() const { return c.back(); }
// deque ,queue , ( )
//
void push(const value_type& __x) { c.push_back(__x); }
//
void pop() { c.pop_front(); }
};
//
template <class _Tp, class _Sequence>
bool
operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
{
return __x.c == __y.c;
}
//
template <class _Tp, class _Sequence>
bool
operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
{
return __x.c < __y.c;
}
...
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
leetcode || 116、Populating Next Right Pointers in Each Nodeproblem: Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node,...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.