problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Private 属性 | 所有成员列表
acwing::acwing20::MyQueue类 参考

#include <acwing.h>

Public 成员函数

 MyQueue ()
 Initialize your data structure here 更多...
 
bool empty () const
 Returns whether the queue is empty 更多...
 
int peek ()
 Get the front element 更多...
 
int pop ()
 Removes the element from in front of queue and returns that element 更多...
 
void push (int x)
 Push element x to the back of queue 更多...
 

Private 属性

vector< int > main
 
vector< int > tmp
 

详细描述

在文件 acwing.h1711 行定义.

构造及析构函数说明

◆ MyQueue()

acwing::acwing20::MyQueue::MyQueue ( )

Initialize your data structure here

在文件 acwing.cpp5234 行定义.

5234 {
5235 main = vector<int>();
5236 tmp = vector<int>();
5237 }
vector< int > tmp
Definition: acwing.h:1714
vector< int > main
Definition: acwing.h:1713

成员函数说明

◆ empty()

bool acwing::acwing20::MyQueue::empty ( ) const

Returns whether the queue is empty

返回
Whether the queue is empty

在文件 acwing.cpp5268 行定义.

5268{ return main.empty(); }

◆ peek()

int acwing::acwing20::MyQueue::peek ( )

Get the front element

返回
The front element

在文件 acwing.cpp5255 行定义.

5255 {
5256 while(main.size() != 1) {
5257 tmp.push_back(main.back());
5258 main.pop_back();
5259 }
5260 const auto ret = main.back();
5261 while(!tmp.empty()) {
5262 main.push_back(tmp.back());
5263 tmp.pop_back();
5264 }
5265 return ret;
5266 }

◆ pop()

int acwing::acwing20::MyQueue::pop ( )

Removes the element from in front of queue and returns that element

返回
The element from in front of queue

在文件 acwing.cpp5241 行定义.

5241 {
5242 while(main.size() != 1) {
5243 tmp.push_back(main.back());
5244 main.pop_back();
5245 }
5246 const auto ret = main.back();
5247 main.pop_back();
5248 while(!tmp.empty()) {
5249 main.push_back(tmp.back());
5250 tmp.pop_back();
5251 }
5252 return ret;
5253 }

◆ push()

void acwing::acwing20::MyQueue::push ( int  x)

Push element x to the back of queue

参数
xThe element to be pushed back into the queue

在文件 acwing.cpp5239 行定义.

5239{ main.push_back(x); }

类成员变量说明

◆ main

vector<int> acwing::acwing20::MyQueue::main
private

在文件 acwing.h1713 行定义.

◆ tmp

vector<int> acwing::acwing20::MyQueue::tmp
private

在文件 acwing.h1714 行定义.


该类的文档由以下文件生成: