Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- vector
- c++
- directx
- 라인트레이서
- queue
- WinAPI
- Deque
- Arduino
- html
- 아두이노 소스
- list
- Array
- Stack
- priority_queue
- stl
- 수광 소자
- 운영체제
- C언어
- 통계학
- Visual Micro
- set
- 자료구조
- 아두이노 컴파일러
- arduino compiler
- map
- 아두이노
- 컴퓨터 그래픽스
- LineTracer
- Algorithm
- 시스템프로그래밍
Archives
- Today
- Total
Kim's Programming
STL(Standard Template Library) - Container - Queue 본문
큐는 선입선출의 자료구조로 먼저 들어온 데이터가 제일 먼저 출력되는 구조의 자료구조입니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include<iostream> #include<queue> void print(std::queue<int> Print_Queue) { while (!Print_Queue.empty()) { std::cout << Print_Queue.front()<<" "; Print_Queue.pop(); } std::cout << std::endl; } void main() { //Queue doesn't have Iterator std::queue<int> Queue; std::queue<int> Queue_Cpoy; //if Queueis empty, empty() function return TRUE if (Queue.empty()) { std::cout << "Queue is Empty" << std::endl; } //push(x) function writes 'x' to the rear of this Queue (FIFO) Queue.push(3); Queue.push(7); Queue.push(1); Queue.push(3); Queue.push(4); Queue.push(5); Queue.push(9); print(Queue); //'=' operator can copy to another Queue, prvious data will be deleted Queue_Cpoy = Queue; print(Queue_Cpoy); //back() function read data from rear of this Queue std::cout <<"Rear data ->" <<Queue.back() << std::endl; //front() function read data from front of this Queue std::cout << "Front data ->" << Queue.front() << std::endl; //pop() function remove data from front of this Queue (FIFO) print(Queue); Queue.pop(); print(Queue); //size() function display this Queue's size std::cout <<"The Size of Queue : "<< Queue.size() << std::endl; //x1.swap(x2) function swap 'x1' and 'x2' Queue.swap(Queue_Cpoy); print(Queue); print(Queue_Cpoy); //emplace(x) function writes 'x' to rear of this Queue Queue.emplace(11); print(Queue); } | cs |
각 함수들의 기능들을 알아보겠습니다.
- empty()
큐가 비어있는지 확인합니다. 비어있으면 true를 비어있지 않으면 false를 리턴합니다. - push(x)
큐 뒤쪽으로 데이터 x를 씁니다. - Operator =
a=b인경우 큐 b의 데이터를 큐 a에 모두 넣습니다. 기존의 큐a의 데이터는 삭제됩니다. - back()
큐에서 큐 가장 마지막 데이터를 리턴합니다. - front()
규에서 가장 앞에 있는 데이터를 리턴합니다. - pop()
큐에서 가장 앞에 있는 데이터를 삭제합니다. - size()
현재 큐의 사이즈를 리턴합니다. - swap()
a.swap(b)인 경우 큐 a와 큐 b의 내용을 완전히 교체합니다. - emplace(x)
x를 큐의 뒤쪽에 넣습니다.
'STL - Container' 카테고리의 다른 글
STL(Standard Template Library) - Container - Priority Queue (0) | 2016.01.28 |
---|---|
STL(Standard Template Library) - Container - Deque (0) | 2016.01.27 |
STL(Standard Template Library) - Container - Stack (0) | 2016.01.27 |
STL(Standard Template Library) - Container - Vector (0) | 2016.01.22 |
STL(Standard Template Library) - Container - List (0) | 2016.01.22 |