C++
2017.02.14 17:15

STL queue 사용법

조회 수 28472 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print



1. 전처리
#include<queue>
using namespace std;
 
2. 선언
queue<테이터형> Queue;
 
3. 삽입
값을 삽입한다.
 
Queue.push(데이터);
 
4. 참조
가장 먼저 추가된 데이터를 가져온다.
 
변수 = Queue.front();
 
5. 삭제
가장 먼저 추가된 데이터를 삭제한다.
Queue.pop();
 
6. 갯수
큐가 가지는 항목의 수를 가져온다.
 
변수 = Queue.size();
 
7. 확인
큐가 비어 있는지 검사한다.
false : 큐에 항목이 있음.
true   : 큐에 항목이 없음.



#include<queue>

queue<int> Q  //Q라는 이름의 int 요소들로 구성된 큐 선언
Q.push(값)  //큐 Q에 값을 넣는다. 리턴 값이 없다.
Q.pop()  //큐 Q의 front를 삭제한다. 리턴 값이 없다.
Q.front()  //큐 Q의 front를 리턴한다. front는 삭제되지 않는다. (peek기능)
Q.back()  //큐 Q의 back를 리턴한다. back는 삭제되지 않는다. (peek기능)
Q.size()  //큐 Q의 크기(구성 요소 갯수)를 리턴한다.
Q.empty()  //큐 Q가 비어있으면(요소가 없으면) 를 1(True)리턴하고 비어있지 않으면 0(False)를 리턴한다.


 
Queue.empty();


#include<queue>
using namespace std;
 
int main(void)
{
queue<char> Queue;
 
Queue.push('A');
Queue.push('B');
Queue.push('C');
 
cout << "Queue Size : " << Queue.size() << endl;
 
cout << "Queue Items" << endl;
 
while( ! Queue.empty() )
{
cout << Queue.front() << endl;
Queue.pop(); 
}
 
return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main(){
 
    queue<int> Q;
 
    cout << "size of queue: " << Q.size() << endl;
    cout << "Is queue empty?: " << Q.empty() << endl<<endl;
 
    Q.push(1);
    Q.push(2);
    Q.push(3);
 
    cout << "size of queue: " << Q.size() << endl;
    cout << "Is queue empty?: " << Q.empty() << endl << endl;
 
    cout << "Front of queue: " << Q.front() << endl;
    cout << "Back of queue: " << Q.back() << endl;
    cout << "size of queue: " << Q.size() << endl << endl;
 
    Q.pop();
 
    cout << "size of queue after popped: " << Q.size() << endl;
    cout << "Front of queue: " << Q.front() << endl;
 
 
    return 0;
}




http://www.cplusplus.com/reference/queue/queue/


FIFO queue
queues are a type of container adaptor, specifically designed to operate in a FIFO context (first-in first-out), where elements are inserted into one end of the container and extracted from the other.

queues are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are pushed into the "back" of the specific container and popped from its "front".

The underlying container may be one of the standard container class template or some other specifically designed container class. This underlying container shall support at least the following operations:
  • empty
  • size
  • front
  • back
  • push_back
  • pop_front

The standard container classes deque and list fulfill these requirements. By default, if no container class is specified for a particular queue class instantiation, the standard container deque is used.

Template parameters

T
Type of the elements.
Aliased as member type queue::value_type.
Container
Type of the internal underlying container object where the elements are stored.
Its value_type shall be T.
Aliased as member type queue::container_type.

Member types

member typedefinitionnotes
value_typeThe first template parameter (T)Type of the elements
container_typeThe second template parameter (Container)Type of the underlying container
size_typean unsigned integral typeusually the same as size_t

Member functions


Non-member function overloads


Non-member class specializations


Dreamy의 코드 스크랩

내가 모으고 내가 보는

List of Articles
번호 분류 제목 날짜 조회 수 추천 수
506 LINUX awk 명령어 사용법 1 2006.02.16 114619 15
505 MFC CString 에서 형변환 함수들 총정리 2010.11.29 102707 0
504 Android adb am 명령어 ; app 실행 및 Intent 전송 2013.08.12 100255 0
503 Android [GIT 사용법] Git Tutorial 2011.12.26 96465 0
502 일반 ┗ bat(배치)파일 문법 2007.08.06 93474 8
501 LINUX [Shell Script] 리눅스 쉘(Shell) 스크립트 2014.09.23 86755 0
500 JAVA JAVA String 클래스 메소드 정리 1 2015.02.05 84930 0
499 LINUX [Shell Script] 쉘 스크립트에서의 사칙연산과 문자열 자르기 2014.11.01 81740 0
498 C# StringBuilder로 문자열 처리를 빠르게 2012.12.04 77937 0
497 LINUX du 명령어 사용법(디스크 용량 확인) 1 2012.05.31 77437 0
496 Python BeautifulSoup으로 웹에 있는 데이터 긁어오기 2013.04.08 76922 0
495 Android [GIT 사용법] 초보자가 알아두면 좋을 명령어 정리 1 2011.12.26 66476 0
494 LINUX errno.h - system error numbers 2013.01.09 65811 0
493 MFC API를 이용하는 유니코드와 ANSI 문자열간의 변환 방법 2006.04.14 63087 0
492 일반 findstr 사용법 - window용 find, grep 명령 2014.02.04 63074 0
목록
Board Pagination ‹ Prev 1 2 3 4 5 6 7 8 9 10 ... 34 Next ›
/ 34

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5