本文整理汇总了C++中stack类的典型用法代码示例。如果您正苦于以下问题:C++ stack类的具体用法?C++ stack怎么用?C++ stack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了stack类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ejecutar
//.........这里部分代码省略.........
}else{
if (set_tmp)
arg1 = new RDecimal();
((RDecimal*)arg1)->setValue(pow(((RNumeric*)arg2)->getDecimalValue(), ((RNumeric*)arg3)->getDecimalValue()));
}
}else{
cout << "Error de tipos en linea " << ri->linea << " , no se puede multiplicar " << *arg2->get_class()->getValue() << " con " << *arg3->get_class()->getValue() << endl;
fin_error = true;
}
break;
case MOD :
if (arg2->is_numeric() && arg3->is_numeric()){
if (!set_tmp && arg1->is_int() || arg2->is_int() && arg3->is_int()){
if (set_tmp)
arg1 = new RInteger();
((RInteger*)arg1)->setValue(((RInteger*)arg2)->getValue() % ((RInteger*)arg3)->getValue());
}else{
if (set_tmp)
arg1 = new RDecimal();
((RDecimal*)arg1)->setValue(((RNumeric*)arg2)->mod((RNumeric*)arg3));
}
}else{
cout << "Error de tipos en linea " << ri->linea << " , no se puede multiplicar " << *arg2->get_class()->getValue() << " con " << *arg3->get_class()->getValue() << endl;
fin_error = true;
}
break;
case SIZE:
if (arg2->type == RARRAY){
arg1= ((RArray*)arg2)->size();
} else if (arg2->type == RSTRING) {
arg1 = new RInteger(((RString*)arg2)->size());
} else if (arg2->type == RCLASS) {
if (((RClass*)arg2)->respond_to(new RString("size"))){
call_stack.push(it);
new_scope();
excecuting_current_class = (RClass*)arg2;
function_info* funcion = excecuting_current_class->get_function_info((RString*)arg3);
if (funcion->param_count == argument_stack.size()){
it = funcion->codigo->begin();
return_stack.push(ri->arg1);
}else{
cout << "Error en linea " << ri->linea << ": cantidad erronea de argumentos, se esperaban " << funcion->param_count << " pero se encontraron " << argument_stack.size() << endl;
fin_error = true;
}
} else {
cout << "Error en linea " << ri->linea << ": el metodo " << *arg3->to_s()->getValue() << " no esta definido para " << *arg2->to_s()->getValue() << endl;
fin_error = true;
}
} else {
cout << "Error en linea " << ri->linea << ": no se puede ejecutar size de " << *arg2->get_class()->getValue() << endl;
fin_error = true;
}
break;
case IF :
if (!((RBool*)arg1)->getValue())
it = descartar_if(it);
cond_stack.push(((RBool*)arg1)->getValue());
break;
case ELSIF : if (!((RBool*)arg1)->getValue()) it = descartar_if(it); else { cond_stack.pop(); cond_stack.push(((RBool*)arg1)->getValue());} break;
case ELSIFCOND : if (cond_stack.top()) it = descartar_hasta_end(it); break;
case ELSE : if (cond_stack.top()) it = descartar_hasta_end(it); break;
case END : cond_stack.pop(); break;
case WHILE :
if (((RBool*)ri->arg1)->getValue())
while_stack.push(it);
else
开发者ID:afast,项目名称:compiladores,代码行数:67,代码来源:stack.cpp
示例2: push
/**************************************************************/
#include "bbi.h"
#include "bbi_prot.h"
CodeSet code; /* 코드 세트 */
int startPc; /* 실행 시작행 */
int Pc = -1; /* 프로그램 카운터 -1: 실행중 아님*/
int baseReg; /* 베이스 레지스터 */
int spReg; /* 스택 포인터 */
int maxLine; /* 프로그램 끝행 */
vector<char*> intercode; /* 변환이 끝난 내부 코드 저장 */
char *code_ptr; /* 내부 코드 분석용 포인터 */
double returnValue; /* 함수 반환 값 */
bool break_Flg, return_Flg, exit_Flg; /* 제어용 플래그 */
Mymemory Dmem; /* 메모리 */
vector<string> strLITERAL; /* 문자열 리터럴 저장 */
vector<double> nbrLITERAL; /* 수치 리터럴 저장 */
bool syntaxChk_mode = false; /* 구문 검사일 때 참 */
extern vector<SymTbl> Gtable; /* 글로벌 심볼 테이블 */
class Mystack { /* stack<double> 의 랩퍼 */
private:
stack<double> st;
public:
void push(double n) { st.push(n); } /* 넣기 */
int size() { return (int)st.size(); } /* 크기 */
开发者ID:KrDevSec,项目名称:MyCustomBBICompiler,代码行数:26,代码来源:bbi_code.cpp
示例3: enqueue
void enqueue(int x){
stack1.push(x);
}
开发者ID:shrawanraina,项目名称:Eclipse,代码行数:3,代码来源:_queueUsingStack.cpp
示例4: llena_pila
void llena_pila(stack<int> &pila, int tam) {
for (int i = 0; i < tam; ++i) {
pila.push(i);
}
}
开发者ID:cedoduarte,项目名称:DuPractices1,代码行数:5,代码来源:main.cpp
示例5: maker
/***********************************************************************
* *
* Name: maker Date: 28.09.00 *
* Author: Evgeni Chernyaev Revised: *
* *
* Function: Executes basic arithmetic operations on values in the top *
* of the stack. Result is placed back into the stack. *
* This function is used by engine(). *
* *
* Parameters: *
* op - code of the operation. *
* val - stack of values. *
* *
***********************************************************************/
static int maker(int op, stack<double> & val)
{
if (val.size() < 2) return EVAL::ERROR_SYNTAX_ERROR;
double val2 = val.top(); val.pop();
double val1 = val.top();
switch (op) {
case OR: // operator ||
val.top() = (val1 || val2) ? 1. : 0.;
return EVAL::OK;
case AND: // operator &&
val.top() = (val1 && val2) ? 1. : 0.;
return EVAL::OK;
case EQ: // operator ==
val.top() = (val1 == val2) ? 1. : 0.;
return EVAL::OK;
case NE: // operator !=
val.top() = (val1 != val2) ? 1. : 0.;
return EVAL::OK;
case GE: // operator >=
val.top() = (val1 >= val2) ? 1. : 0.;
return EVAL::OK;
case GT: // operator >
val.top() = (val1 > val2) ? 1. : 0.;
return EVAL::OK;
case LE: // operator <=
val.top() = (val1 <= val2) ? 1. : 0.;
return EVAL::OK;
case LT: // operator <
val.top() = (val1 < val2) ? 1. : 0.;
return EVAL::OK;
case PLUS: // operator '+'
val.top() = val1 + val2;
return EVAL::OK;
case MINUS: // operator '-'
val.top() = val1 - val2;
return EVAL::OK;
case MULT: // operator '*'
val.top() = val1 * val2;
return EVAL::OK;
case DIV: // operator '/'
if (val2 == 0.0) return EVAL::ERROR_CALCULATION_ERROR;
val.top() = val1 / val2;
return EVAL::OK;
case POW: // operator '^' (or '**')
errno = 0;
val.top() = pow(val1,val2);
if (errno == 0) return EVAL::OK;
default:
return EVAL::ERROR_CALCULATION_ERROR;
}
}
开发者ID:vvolkl,项目名称:DD4hep,代码行数:65,代码来源:Evaluator.cpp
示例6: getmin
int getmin(void){
if (s1.empty() || s2.empty()) return s1.empty()?s2.top().second:s1.top().second;
return min(s1.top().second,s2.top().second);
}
开发者ID:ZaMaZaN4iK,项目名称:Algorithms,代码行数:4,代码来源:queue_with_min-O(1).cpp
示例7: main
int main()
{
int n;
char ch;
while(cin>>n)
{
int i,j,k=0;
arry[0]=n;
ch=getchar();
while(ch!='\n')
{
cin>>arry[++k];
ch=getchar();
}
k++;
int flag=1,s;
for(i=0;i<k;i++)
{
if(arry[i]<0)
{
team1.push(arry[i]);
team2.push(arry[i]*(-1));
}
else if(arry[i]>0)
{
if(team2.empty())
{
flag=0;
break;
}
if(arry[i]!=team2.top())
{
flag=0;
break;
}
else
{
team2.pop();
s=0;
while(team1.top()>0)
{
s=s+team1.top();
team1.pop();
}
if(s>=arry[i])
{
flag=0;
break;
}
team1.pop();
team1.push(arry[i]);
}
}
}
if(!team2.empty()) flag=0;
if(flag) cout<<":-) Matrioshka!"<<endl;
else cout<<":-( Try again."<<endl;
while(!team1.empty())
team1.pop();
while(!team2.empty())
team2.pop();
}
return 0;
}
开发者ID:iFighting,项目名称:Algorithm-Contests,代码行数:64,代码来源:Generalized+Matrioshkas.cpp
示例8: color
void color(int x, int y, int c){
sx.push(x);
sy.push(y);
sc.push(c);
si.push(0);
while(!sx.empty()){
int x = sx.top();
int y = sy.top();
int c = sc.top();
int i = si.top();
sx.pop(), sy.pop(), sc.pop(), si.pop();
if(i == 0){
if(c) bcc[x][y].push_back(c);
bvis[x][y] = 1;
}
while(i < 4){
if(ok2(x + dx[i], y + dy[i]) && !bvis[x + dx[i]][y + dy[i]]){
if(low[x + dx[i]][y + dy[i]] >= dfn[x][y]){
bcc[x][y].push_back(++col);
sx.push(x);
sy.push(y);
sc.push(c);
si.push(i+1);
sx.push(x + dx[i]);
sy.push(y + dy[i]);
sc.push(col);
si.push(0);
goto T;
}
else{
sx.push(x);
sy.push(y);
sc.push(c);
si.push(i+1);
sx.push(x + dx[i]);
sy.push(y + dy[i]);
sc.push(c);
si.push(0);
goto T;
}
}
i++;
}
T:;
}
}
开发者ID:koosaga,项目名称:olympiad,代码行数:46,代码来源:camp12_sokoban_stack.cpp
示例9: gol
void gol() {
while (!stk.empty())
stk.pop();
}
开发者ID:Andrei1998,项目名称:Info,代码行数:4,代码来源:main.cpp
示例10: pop
void pop() {
if (s_1.empty()) {
transfere();
}
s_1.pop();
}
开发者ID:ulisesmx,项目名称:exercises,代码行数:6,代码来源:stack_queue.cpp
示例11: Restore
void MWinDeviceImpl::Restore()
{
assert(not mState.empty());
mRenderTarget->RestoreDrawingState(mState.top());
mState.pop();
}
开发者ID:BackupTheBerlios,项目名称:japi-svn,代码行数:6,代码来源:MWinDevice.cpp
示例12: Right_Extension
void Right_Extension(string &SeedStr)
{
int i,j;
int index;
int difpos;//得分相差很小的两条contig之间第一个不同的点
int MinCandidateLength;//candidate序列中的最短长度
int TotalReads;//总共的reads
int MatchReads;//match上的reads
int NumOfNotInf;//在所有candidate有匹配的数目
int dir;//表示方向,1表示向右,-1表示向左
string MaxScoreString;//获得最大得分的字符串
string SubSeedStr;
string TempSubSeedStr;
bool IsExtension;
bool IsQuit;
bool IsFitCondition;
double perc;
set<int> used;
int circleLen(0);
bool circled(false);
while(1)
{
Node nd;
Node tempnd;//保存从栈顶出来的元素
while(!st.empty()) st.pop();//清空栈中元素
SubSeedStr=SeedStr.substr(SeedStr.size()-lib[1].MinOverLap);//取出长度为k-mer的字串去查找index
index=StrtoInt[SubSeedStr];
nd.CurStr=SubSeedStr;
nd.index=index;
st.push(nd);
IsExtension=false;
IsQuit=false;
tempvec.clear();
while(!st.empty()||tempvec.size()>0)//栈不为空或者临时容器的size大于1继续
{
if(st.empty()&&tempvec.size()>0)//栈中为空并且不止一个可能节点
{
MinCandidateLength=tempvec[0].CurStr.size();
for(i=1;i<tempvec.size();i++)//找出candidate序列中的最短长度
{
if(tempvec[i].CurStr.size()<MinCandidateLength) MinCandidateLength=tempvec[i].CurStr.size();
}
IsFitCondition=false;
for(i=1;i<=FileNum;i++)
{
for(j=0;j<tempvec.size();j++)
{
if(SeedStr.size()<(lib[i].MinSpan+lib[i].MaxSpan)/2) continue;
if(tempvec[j].score==NegativeMin) continue;
TotalReads=0;
MatchReads=0;
double gs=GetScore(tempvec[j].SupportStr,SeedStr,tempvec[j].CurStr.substr(0,GetMin(MinCandidateLength,lib[1].MinSpan)),i,TotalReads,MatchReads,1);
if(TotalReads==0)
{
tempvec[j].score=NegativeMin;
}
else
{
if(MatchReads)
{
perc=MatchReads*1.0/TotalReads;
tempvec[j].score+=gs*perc;
}
else
{
if(TotalReads==1) tempvec[j].score=0;
else tempvec[j].score=NegativeMin;
}
}
}
if(tempvec.size()>0)
{
sort(tempvec.begin(),tempvec.end(),cmp2);
NumOfNotInf=0;
if(IsAllNegativeAndNoFit(tempvec,NumOfNotInf))
{
IsQuit=true;
break;
}
int veclen=tempvec.size();
if(NumOfNotInf==1)
{
for(j=veclen-1;j>=0;j--)
{
if(tempvec[j].score==NegativeMin) tempvec.pop_back();
else break;
}
}
else
{
for(j=veclen-1;j>=0;j--)
{
if(tempvec[j].score<0) tempvec.pop_back();
else break;
}
}
if(IsAllInCondition(tempvec,i)==true)
{
//.........这里部分代码省略.........
开发者ID:bioinfomaticsCSU,项目名称:ISEA,代码行数:101,代码来源:extend.cpp
示例13: push
void push(int x){
int minim=s1.empty()?x:min(x,s1.top().second);
s1.push(make_pair(x,minim));
}
开发者ID:ZaMaZaN4iK,项目名称:Algorithms,代码行数:4,代码来源:queue_with_min-O(1).cpp
示例14: empty
bool empty(void){
return s1.empty() && s2.empty();
}
开发者ID:ZaMaZaN4iK,项目名称:Algorithms,代码行数:3,代码来源:queue_with_min-O(1).cpp
示例15: transfere
void transfere() {
while (!s_2.empty()) {
s_1.push(s_2.top());
s_2.pop();
}
}
开发者ID:ulisesmx,项目名称:exercises,代码行数:6,代码来源:stack_queue.cpp
示例16: push
void push(int data) {
s_2.push(data);
}
开发者ID:ulisesmx,项目名称:exercises,代码行数:3,代码来源:stack_queue.cpp
示例17: GetDit
void GetDit(int num){
while(num){
s.push(num % 10);
num /= 10;
}
}
开发者ID:zhangsh950618,项目名称:algorithm,代码行数:6,代码来源:算法训练+数位分离.cpp
示例18: front
int front() {
if (s_1.empty()) {
transfere();
}
return s_1.top();
}
开发者ID:ulisesmx,项目名称:exercises,代码行数:6,代码来源:stack_queue.cpp
示例19: hasNext
/** @return whether we have a next smallest number */
bool hasNext() {
if(s.empty())
return false;
return true;
}
开发者ID:Time1ess,项目名称:MyCodes,代码行数:6,代码来源:solution.cpp
示例20: clear
void clear(){
while(!(head->empty()))head->pop();
while(!(rear->empty()))rear->pop();
}
开发者ID:shixv,项目名称:test,代码行数:4,代码来源:2.cpp
注:本文中的stack类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论