queue 클래스
A template container adaptor class that provides a restriction of functionality for some underlying container type, limiting access to the front and back elements. Elements can be added at the back or removed from the front, and elements can be inspected at either end of the queue.
template <
class Type,
class Container = deque<Type>
>
class queue
매개 변수
형식
The element data type to be stored in the queueContainer
The type of the underlying container used to implement the queue.
설명
The elements of class Type stipulated in the first template parameter of a queue object are synonymous with value_type and must match the type of element in the underlying container class Container stipulated by the second template parameter. The Type must be assignable, so that it is possible to copy objects of that type and to assign values to variables of that type.
Suitable underlying container classes for queue include deque and list, or any other sequence container that supports the operations of front, back, push_back, and pop_front. The underlying container class is encapsulated within the container adaptor, which exposes only the limited set of the sequence container member functions as a public interface.
The queue objects are equality comparable if and only if the elements of class Type are equality comparable, and are less-than comparable if and only if the elements of class Type are less-than comparable.
There are three types of container adaptors defined by the STL: stack, queue, and priority_queue. Each restricts the functionality of some underlying container class to provide a precisely controlled interface to a standard data structure.
The stack class supports a last-in, first-out (LIFO) data structure. A good analogue to keep in mind would be a stack of plates. Elements (plates) may be inserted, inspected, or removed only from the top of the stack, which is the last element at the end of the base container. The restriction to accessing only the top element is the reason for using the stack class.
The queue class supports a first-in, first-out (FIFO) data structure. A good analogue to keep in mind would be people lining up for a bank teller. Elements (people) may be added to the back of the line and are removed from the front of the line. Both the front and the back of a line may be inspected. The restriction to accessing only the front and back elements in this way is the reason for using the queue class.
The priority_queue class orders its elements so that the largest element is always at the top position. It supports insertion of an element and the inspection and removal of the top element. A good analogue to keep in mind would be people lining up where they are arranged by age, height, or some other criterion.
생성자
Constructs a queue that is empty or that is a copy of a base container object. |
형식 정의
A type that provides the base container to be adapted by the queue. |
|
부호 없는 정수 형식은 queue의 요소 갯수를 표현할 수 있습니다. |
|
A type that represents the type of object stored as an element in a queue. |
멤버 함수
Returns a reference to the last and most recently added element at the back of the queue. |
|
Tests if the queue is empty. |
|
Returns a reference to the first element at the front of the queue. |
|
Removes an element from the front of the queue. |
|
Adds an element to the back of the queue. |
|
다음 queue내에 있는 요소 수를 반환합니다. |
요구 사항
Header: <queue>
네임스페이스: std