本文整理汇总了C++中stack::size方法的典型用法代码示例。如果您正苦于以下问题:C++ stack::size方法的具体用法?C++ stack::size怎么用?C++ stack::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack
的用法示例。
在下文中一共展示了stack::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MenuException
virtual shared_ptr<MenuComponent> move(MenuLeaf& m, KeyButton& k) {
switch (k.get_key()) {
case BUTTON_UP:
return (history.top().get().get_previous_element());
case BUTTON_DOWN:
return (history.top().get().get_next_element());
case BUTTON_LEFT:
if (history.size() > 1) {
history.top().get().home();
history.pop();
}
return (history.top().get().get_active_element());
case BUTTON_RIGHT:
return (history.top().get().get_active_element());
default:
throw MenuException((string("Unexpected key ") + string(k)).c_str());
break;
}
}
示例2: shift_reduce
bool shift_reduce( const T& c ) {
while ( stack_.top().distance() < width_ ) {
// && stack_.top().type() == peakfind::Down ) { // discard narrow 'down' state
stack_.pop();
if ( stack_.empty() ) {
stack_.push( c );
return false;
}
}
if ( stack_.top().type() == c.type() ) // marge
stack_.top() += c; // marge
// if (Up - Down)|(Down - Up), should push counter and wait for next state
if ( stack_.top().type() != c.type() )
stack_.push( c );
return stack_.size() >= 3;
};
示例3: main
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d %d", lf+i, rg+i);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (lf[i] > lf[j] && rg[i] < rg[j])
adj[j].push_back(i);
}
}
int maxi = 0;
for (int i = 0; i < n; i++)
hei[i] = -1;
for (int i = 0; i < n; i++) {
dfs(i);
if (hei[maxi] < hei[i])
maxi = i;
}
printf("%d\n", hei[maxi]);
while (hei[maxi] != 1) {
st.push(maxi+1);
for (int i = 0; i < adj[maxi].size(); i++) {
if (hei[adj[maxi][i]] == hei[maxi] - 1) {
maxi = adj[maxi][i];
break;
}
}
}
st.push(maxi+1);
while (st.size() > 1) {
printf("%d ", st.top());
st.pop();
}
printf("%d\n", st.top());
}
示例4: GFXPopGlobalEffects
GFXBOOL /*GFXDRVAPI*/ GFXPopGlobalEffects()
{
if ( GlobalEffects.empty() )
return false;
//VSFileSystem::Fprintf (stderr,"GES %d",GlobalEffects.size());
for (int i = 0; i < GFX_MAX_LIGHTS; i++)
if (GlobalEffects.top()[i])
glEnable( GL_LIGHT0+i );
if (GlobalEffectsFreelist.size() >= 10)
delete[] GlobalEffects.top();
else
GlobalEffectsFreelist.push(GlobalEffects.top());
GlobalEffects.pop();
GFXLightContextAmbient( GlobalEffectsAmbient.top() );
GlobalEffectsAmbient.pop();
return true;
}
示例5: main
int main()
{
int i,n;
char s;
cin>>n;
for(i=1;i<=n;i++){
cin>>s;
if(st.empty()){
st.push(s);
continue;
}
char r=st.top();
if(r!=s){
st.pop();
}else{
st.push(s);
}
}
cout<<st.size();
}
示例6: op
void op(string& opCode)
{
if(s.size() >= 2) {
double a = s.top(); s.pop();
double b = s.top(); s.pop();
double result;
if(opCode == "+") result = b + a;
else if(opCode == "-") result = b - a;
else if(opCode == "*") result = b * a;
else if(opCode == "/") result = b / a;
else if(opCode == "%") result = fmod(b, a);
else {
cout << "unknown operator " << opCode << "\n";
return;
}
cout << result << "\n";
s.push(result);
} else
cout << "need two numbers\n";
}
示例7: handleSelfCloseTags
/* ------------------------------- To handle self closing tags on stack ----------------------------------*/
void XMLParser::handleSelfCloseTags(XmlReader newxrdPtr, stack<shared_ptr <AbstractXmlElement>> &impStack, string element, string temp, size_t s)
{
using sPtr = shared_ptr < AbstractXmlElement >;
if (impStack.size() != 0){
sPtr pop0 = impStack.top();
impStack.pop();
newxrdPtr.position(s + 1);
sPtr child = makeTaggedElement(newxrdPtr.tag());
if (containsTagsText(newxrdPtr, child)){}
containsAttribute(newxrdPtr, child);
child->selfCloseTag(1);
if (pop0->numofChild() > 0) {
pop0->addChild(child);
pop0->getNumofChilds(pop0->numofChild() - 1);
impStack.push(pop0);
}
}
}
示例8: item
// Display the stack in "pop" order
template<> void debug::dump<stack<int>>(const string& msg, const stack<int>& indecies) noexcept
{
cout << msg;
struct Hack : public stack<int> {
static int item(int i, const stack<int>& stack_ref)
{
return (stack_ref.*&Hack::c)[i];
}
};
for(int i = indecies.size() - 1; i >= 0; --i) {
// for(int i = 0; i < indecies.size(); ++i) {
cout << Hack::item(i, indecies) << ", ";
}
cout << endl;
}
示例9: infixToPostfix
char* infixToPostfix(char *s){
int i=0; //loop variable
int prior,n;
char *postfix;
while(s[i]!='\0'){
prior=priority(s[i]);
if(prior<0)
expres.push(s[i]);
else insert(s[i],prior);
i++;
}
while(!aux.empty()){
expres.push(aux.top());
aux.pop();
}
n=expres.size();
postfix=new char[n+1];
FOR(i,n){
postfix[n-i-1]=expres.top();
expres.pop();
}
示例10: undo
//This is also a helper function for UNDO command, return the previous turn result
void Board::undo() {
if (undo_counter < 10) {
if (undo_list.size() != 0) { //undo_list contains some previous turns
gameboard = undo_list.top();
undo_list.pop();
if (previous_turn() == 1) {
undo();
}
else { //undo_list is empty
turn = -1;
undo_counter++;
show();
cout << 10 - undo_counter << " UNDO remain\n";
}
}
else
cout << "no more undo steps" << endl;
}
else
cout << "at most undo 10 times\n";
}
示例11: push
void specialStack::push(int data){
s.push(data);
if(sm.empty()){
Min *tmp = new Min;
tmp->data = data;
tmp->ind = 0;
sm.push(tmp);
}
else {
Min *t = sm.top();
if(t->data < data){
sm.top()->ind++;
}
else {
Min *tmp = new Min;
tmp->data = data;
tmp->ind = s.size()-1;
sm.push(tmp);
}
}
}
开发者ID:linearregression,项目名称:geeksforgeeks,代码行数:21,代码来源:8.design-and-implement-special-stack-data-structure.cpp
示例12: fact
inline llint fact( llint n ) {
llint ret = 1;
int l1,l2;
l1 = prost.size();
for( int x = 0; x < l1 && n != 1; x++ ) {
uzet.push( x );
while( n % prost[x] == 0 )
n /= prost[x], niz[x] *= prost[ x ];
if( niz[ x ] == 1 )
uzet.pop();
}
if( n != 1 ) {
ret *= calc( n, n );
}
while( uzet.size() ) {
ret *= calc( niz[ uzet.top() ], prost[ uzet.top() ] );
niz[ uzet.top() ] = 1;
uzet.pop();
}
return ret;
}
示例13: handleProcInstr
/* ------------------------------- To handle Process Instructions ----------------------------------*/
void XMLParser::handleProcInstr(XmlReader newxrdPtr, stack<shared_ptr <AbstractXmlElement>> &impStack, string element, string temp, size_t s)
{
using sPtr = shared_ptr < AbstractXmlElement >;
if (impStack.size() != 0) {
sPtr pop0 = impStack.top();
impStack.pop();
newxrdPtr.position(s + 1);
sPtr child = makeProcInstrElement(newxrdPtr.tag());
s = newxrdPtr.tag().size() + 1;
vector<string> attrvalue = getManualAttre(getString(s, temp.size() -1 , temp));
for (size_t i = 0; i < attrvalue.size(); i += 2)
{ child->addAttrib(attrvalue[i], attrvalue[i + 1]); }
child->selfCloseTag(1);
if (pop0->numofChild() > 0){
pop0->addChild(child);
pop0->getNumofChilds(pop0->numofChild() - 1);
impStack.push(pop0);
}
}
}
示例14: sort_root
void sort_root(vector<int> &v)
{
vector<vstore> values, temp;
vector<vstore>::iterator it;
vstore pop;
while (sstore.size() != 0)
{
pop = sstore.top();
temp.push_back(pop);
sstore.pop();
}
while (temp.size() != 0)
{
values.push_back(temp[temp.size() - 1]);
temp.pop_back();
}
size_t least = 0;
for (int i = 0; i < values.size() - 1; i++)
{
least = i;
for (int j = i + 1; j < values.size(); ++j)
{
if (v[values[j].second] < v[values[least].second])
{
cond_check = 1;
least = j;
}
}
int idx = values[least].second;
int temp = v[idx];
int idx1 = values[i].second;
int temp1 = v[idx1];
v[values[i].second] = temp;
v[values[least].second] = temp1;
}
for (int i = 0; i < values.size(); i++)
{
sstore.push(values[i]);
}
}
示例15: ptdDoPaintSingleDot
//////////////////////////////////////////////////////////////////////////
// 在dc上绘制单个点像素
void ptdDoPaintSingleDot(HDC hdc)
{
if (flag == 0)
{
num = rand() % max_num;
COLORREF color;
pair<int, int> temp_pots;
temp_pots.first = gaussrand(arr[num][0] * 13, 5);
temp_pots.second = gaussrand(arr[num][1] * 13, 5);
pots_stack.push(temp_pots);
if (pots_stack.size() > 18000)
{
flag = 1;
}
if (arr[num][5] == 1)
{
color = RGB(255, gaussrand(arr[num][3] * 0.5, 60), gaussrand(arr[num][4] * 0.5, 60));
}
else
{
color = RGB(arr[num][2] * 1.2, 255, arr[num][4] * 1.2);
}
SetPixel(hdc, temp_pots.first, temp_pots.second, color);
}
else
{
SetPixel(
hdc,
pots_stack.top().first,
pots_stack.top().second,
RGB(0, 0, 0));
pots_stack.pop();
if (pots_stack.empty())
{
flag = 0;
}
}
}