本文整理汇总了C++中std::stack::push方法的典型用法代码示例。如果您正苦于以下问题:C++ stack::push方法的具体用法?C++ stack::push怎么用?C++ stack::push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::stack
的用法示例。
在下文中一共展示了stack::push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Select
bool Selector::Select(const int i_letter, std::stack<int> & verifier)
{
if (i_letter >= static_cast<int>(data_.size()))
{
return verifier.empty();
}
auto& memo = memo_[i_letter][data_[i_letter]];
if (memo != -1)
{
return memo != 0;
}
if (data_[i_letter] == 1)
{
verifier.push(1);
return Select(i_letter + 1, verifier);
}
if (data_[i_letter] == 0)
{
if (verifier.empty() || ((verifier.top() == 1) && (verifier.size() == 1)))
{
memo = 0;
return false;
}
verifier.pop();
return Select(i_letter + 1, verifier);
}
assert(data_[i_letter] == 2);
verifier.push(1);
if (Select(i_letter + 1, verifier))
{
memo = 1;
return true;
}
return false;
}
示例2: main
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitWindowPosition(0,0);
glutInitWindowSize(800,600);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutCreateWindow("PewPew");
//glEnable(GL_LIGHTING);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
//glShadeModel(GL_SMOOTH);
//glEnable(GL_LIGHT0);
glMatrixMode(GL_PROJECTION);
open_joystick();
mn.add_option(std::string("INFO"),(&info_action));
mn.add_option(std::string("PLAY"),(&run));
mn.add_option(std::string("NEW GAME"),(&new_game));
mn.add_option(std::string("OPTIONS"),(&option_action));
mn.add_option(std::string("QUIT"),(&end_0));
menu_pages.push(&mn);
opt.add_option(std::string("BACK"),(&back));
opt.add_option(std::string("SCORES"),(&scores_action));
opt.add_option(std::string("SOUNDS ON"),(&sound_off),std::string("SOUNDS OFF"),(&sound_on));
scores.add_option(std::string("BACK"), (&back));
info.add_option(std::string("BACK"),(&back));
//GLfloat filter[11] = {0.3,0.28,0.26,0.24,0.22,0.20,0.22,0.24,0.26,0.28,0.3}; //GOOD
//glSeparableFilter2D(GL_SEPARABLE_2D, GL_LUMINANCE, 11, 11, GL_LUMINANCE, GL_FLOAT, filter,filter); //<< segfault !!!
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
//glutIdleFunc(mytimer);
glutTimerFunc(20,mytimer,1);
glutIgnoreKeyRepeat(1);
glutKeyboardUpFunc(kbRelF);
glutSpecialFunc(skbF);
glutKeyboardFunc(kbF);
glutPassiveMotionFunc(mIdleF);
glutMouseFunc(mF);
glutMainLoop();
return 0;
}
示例3: processBinaryOp
void PostfixExprEvaluator::processBinaryOp(const Token &token,
std::stack<Token> &operands)
{
assert(token.type == TokenType::TOK_BINARYOP);
// ensure stack contains two operands
if (operands.size() < 2)
{
throw StackUnderflowException();
}
// fetch operand off the stack
auto op2 = operands.top(); operands.pop();
auto op1 = operands.top(); operands.pop();
Token result;
// if floating point calculation
if (op1.type == TokenType::TOK_FLOAT
|| op2.type == TokenType::TOK_FLOAT)
{
// convert int to float, if neccessary
if (op1.type == TokenType::TOK_INT)
{
op1 = castIntToFloat(op1);
}
if (op2.type == TokenType::TOK_INT)
{
op2 = castIntToFloat(op2);
}
result.type = TokenType::TOK_FLOAT;
result.value.valueFloat = evalBinaryOp<float>
(
op1.value.valueFloat,
op2.value.valueFloat,
token.value.vOpBinary
);
}
else
{
result.type = TokenType::TOK_INT;
result.value.valueInt = evalBinaryOp<int>
(
op1.value.valueInt,
op2.value.valueInt,
token.value.vOpBinary
);
}
operands.push(result);
}
示例4: dd_handlePop
int dd_handlePop()
{
if(dd_handles.empty())
{
for(int i=1;i<=4;i++)
dd_handles.push(dd_handleCount+i);
dd_handleCount += 4;
}
int handle = dd_handles.top();
dd_handles.pop();
return handle;
}
示例5: second
int second (std::stack<int> s)
{
int tmp, second;
tmp = s.top();
s.pop();
second = s.top();
s.push(tmp);
if (DEBUG == 1)
cout << "the 2nd element is : " << second <<"\n";
return second;
}
示例6: dump
void dump()
{
if (stckIn.empty() || !stckOut.empty())
return;
while (!stckIn.empty())
{
stckOut.push(stckIn.top());
stckIn.pop();
}
assert(stckIn.empty());
}
示例7: render
void MovingPlatform::render(std::stack<glm::mat4>& _Stack)
{
//drawing the position of first moving platform
glBindTexture(GL_TEXTURE_2D, textures[0]);
_Stack.push(_Stack.top());
_Stack.top() = glm::translate(_Stack.top(), currentPos);
_Stack.top() = glm::scale(_Stack.top(), glm::vec3(5.0f, 0.1f, 5.0f));
rt3d::setUniformMatrix4fv(shaderProgram, "modelview", glm::value_ptr(_Stack.top()));
rt3d::setMaterial(shaderProgram, material0);
rt3d::drawIndexedMesh(meshObjects[0], meshIndexCount, GL_TRIANGLES);
_Stack.pop();
}
示例8: SDLGui_Open
/* Open a dialog */
void SDLGui_Open(Dialog *new_dlg)
{
if (new_dlg==NULL) {
/* Open main as default */
new_dlg = DlgMainOpen();
}
dlgStack.push(new_dlg);
gui_dlg = dlgStack.top();
gui_dlg->init();
gui_dlg->idle();
}
示例9: Change
void StateManager::Change(State* state)
{
if(states.size() > 0)
{
delete states.top();
states.pop();
}
states.push(state);
state_changed = true;
//states.top().Resume();
}
示例10: grahamScan
//Realiza el algoritmo de Graham de las 3 monedas para hallar el Convex Hull S de una lista de Puntos Q.
//Devuelve una Pila con el resultado clockwise.
void grahamScan(std::list<Point2D> & Q, std::stack<Point2D> & S){
minimal = encontrarMinimal(Q); //Encuentra el minimal izquierda abajo
// std::cout<<"Minimal: "; minimal.print();
borrarMinimal(Q, minimal); //Borra el minimal de la cola
Q.sort(comparePoint2DPolar); //Ordena en forma polar
std::cout<<"Lista ordenada\n"; printList(Q);
eliminarColineales(Q); //Hace limpieza de los puntos colineales, dejando el mas lejano
std::cout<<"Lista ordenada\n"; printList(Q);
//Ubica las 3 primeras monedas
S.push(minimal); //Agrega el primero que es el minimal
//Agrega la segunda y tercera
std::list<Point2D>::iterator it = Q.begin(); //Iterador para recorrer la Q
for(unsigned int i = 0; i < 2 and it != Q.end(); i++, it++){
S.push(*it);
}
//tamanio de Q
unsigned int n = Q.size();
//Loop de Graham Scan
for(unsigned int i = 2; i < n and it != Q.end(); i++, it++){
Point2D ntt = nextToTop(S);
Point2D nt = top(S);
Point2D p = *it;
while(!leftTurn(ntt, nt, p) and (S.size() > 1)){ //Si no froman un giro a la izquierda y queda mas de un elemento en S
// printStack(S);
S.pop(); //Saco el tope de S
ntt = nextToTop(S); //Renuevo los valores y vuelvo a probar
nt = top(S);
}
S.push(p); //Agrego el elemento a S
}
}
示例11: DeserializeInternal
static Value DeserializeInternal(const std::string& _str, std::stack<StackDepthType>& depth_stack)
{
Value v;
std::string str = Trim(_str);
if (str[0] == '{')
{
// Error: Began with a { but doesn't end with one
if (str[str.length() - 1] != '}')
return Value();
depth_stack.push(InObject);
v = DeserializeObj(str, depth_stack);
if ((v.GetType() == NULLVal) || (depth_stack.top() != InObject))
return v;
depth_stack.pop();
}
else if (str[0] == '[')
{
// Error: Began with a [ but doesn't end with one
if (str[str.length() - 1] != ']')
return Value();
depth_stack.push(InArray);
v = DeserializeArray(str, depth_stack);
if ((v.GetType() == NULLVal) || (depth_stack.top() != InArray))
return v;
depth_stack.pop();
}
else
{
// Will never get here unless _str is not valid JSON
return Value();
}
return v;
}
示例12: getPath
void getPath(std::stack<TreeNode*>& path,TreeNode* root, TreeNode* target){
TreeNode* prev = nullptr;
//actually postorder traversal//since I cannot just pop it out need to go back to parent the second time
while(!path.empty() || root){
if(root==target){
path.push(root);
return;
}
if(root){
path.push(root);
root = root->left;
}else if((path.top()->right)==prev){
prev = path.top();
path.pop();
}else{
root = path.top();
prev = root;
root = root->right;
prev = nullptr;
}
}
}
示例13: StartObject
bool Deserializer::StartObject()
{
// not a root object
if (!_state.empty())
{
if (_state.top()->cpp_type() != google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE)
{
_errors.push_back(Trinity::StringFormat("Expected field %s to be a message but got %s instead.", _state.top()->cpp_type_name()));
return false;
}
google::protobuf::Message* containingMessage = _objectState.top();
if (!_state.top()->is_repeated())
_objectState.push(containingMessage->GetReflection()->MutableMessage(containingMessage, _state.top()));
else
_objectState.push(containingMessage->GetReflection()->AddMessage(containingMessage, _state.top()));
}
else if (_objectState.size() != 1)
return false;
return true;
}
示例14: if
virtual void operator++() override{
while (!st.empty()){
auto i = st.top(); st.pop();
if (i.second == 1){
++i.second; st.push(i);
if (i.first->left != nullptr){
st.push({i.first->left, 1});
}
}
else if (i.second == 2){
++i.second; st.push(i);
if (i.first->right != nullptr){
st.push({i.first->right, 1});
}
}
else {
ptr = i.first;
return;
}
}
ptr = nullptr;
}
示例15: dequeue
int MyQueue::dequeue(int& val)
{
if (stackFirst.empty())
return -1;
while(!stackFirst.empty())
{
stackSecond.push(stackFirst.top());
stackFirst.pop();
}
val = stackSecond.top();
stackSecond.pop();
while(!stackSecond.empty())
{
stackFirst.push(stackSecond.top());
stackSecond.pop();
}
return 0;
}