본문 바로가기
C and C++/C and C++ Examples

[Example Codes] queue.push(), queue,back(), queue.front(), queue.pop()

by Henry Cho 2020. 5. 5.
728x90

queue.push(), queue.back(), queue.front(), queue.pop()


// whoIsHoo
// C++에 빠지다

#include <iostream>       
#include <queue>         
using namespace std;

int main()
{
	queue<int> hooQueue;
	
	hooQueue.push(18);
	hooQueue.push(21);
	hooQueue.push(23);
	hooQueue.push(27);
	hooQueue.push(31);

	cout << "The last element is " << hooQueue.back() << endl;
	cout << "The first element is " << hooQueue.front() << endl;

	hooQueue.pop();
	hooQueue.pop();

	cout << endl << "After pop funtion" << endl << endl;

	cout << "The last element is " << hooQueue.back() << endl;
	cout << "The first element is " << hooQueue.front() << endl;

	hooQueue.back() = hooQueue.back() + hooQueue.front();

	cout << "After add back and front elements: " << hooQueue.back() << endl;

	return 0;
}
The last element is 31
The first element is 18

After pop funtion

The last element is 31
The first element is 23
After add back and front elements: 54

예제 코드를 활용하는 방법!!

1. 예제 코드를 보고 직접 컴파일을 해보세요.

2. 예제 코드에서 모르는 부분이 있다면 알려주세요.

3. Flowcharts를 직접 그려보시고 알려주세요.

 

728x90

댓글