当前位置: 首页>>代码示例>>C++>>正文


C++ TStack::pop方法代码示例

本文整理汇总了C++中TStack::pop方法的典型用法代码示例。如果您正苦于以下问题:C++ TStack::pop方法的具体用法?C++ TStack::pop怎么用?C++ TStack::pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TStack的用法示例。


在下文中一共展示了TStack::pop方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char** argv) {

    TStack stack;

    stack.push(Triangle(1, 1, 1));
    stack.push(Triangle(2, 2, 2));
    stack.push(Triangle(3, 3, 3));

    std::cout << stack;


    Triangle t, tmp1, tmp2;

    t = stack.pop(); std::cout << t;
    t = stack.pop(); std::cout << t;
    t = stack.pop(); std::cout << t;

    t = Triangle(15, 15, 15);
    tmp1 = Triangle(20, 15, 15);

    isEqual(t, tmp1);

    tmp1 = t;

    isEqual(t, tmp1);

    return 0;
}
开发者ID:desoo40,项目名称:mai_labs,代码行数:28,代码来源:main.cpp

示例2: print

 //вывод на экран
 void print()
 {
     if(!Data.isempty()) std::cout << "Result is: " << Data.pop() << std::endl;
     else error("cann't res, stack is empty");
     it++;
     //так можно вывести значение переменной x1
     //cout << VM::table.at("x1") << endl;
 }
开发者ID:ivanprosh,项目名称:Lingvo,代码行数:9,代码来源:main.cpp

示例3: sqrt

 //вычисление корня
 void sqrt()
 {
     if(!Data.isempty())
     {
         double x = Data.pop();
         Data.push(std::sqrt(x));
         it++;
     }
     else error("cann't execute sqrt, stack is empty");
 }
开发者ID:ivanprosh,项目名称:Lingvo,代码行数:11,代码来源:main.cpp

示例4: mul

 //умножение
 void mul()
 {
     if(Data.size()>1)
     {
         double x = Data.pop();
         double y = Data.pop();
         Data.push(x*y);
         it++;
     }
     else error("cann't execute mul, stack is empty");
 }
开发者ID:ivanprosh,项目名称:Lingvo,代码行数:12,代码来源:main.cpp

示例5: sub

 //разность
 void sub()
 {
     if(Data.size()>1)
     {
         double y = Data.pop();
         double x = Data.pop();
         Data.push(x-y);
         it++;
     }
     else error("cann't execute add, stack is empty");
 }
开发者ID:ivanprosh,项目名称:Lingvo,代码行数:12,代码来源:main.cpp

示例6: start

 //запуск виртуальной машины
 void start()
 {
     if(Code == nullptr) {
         error("Not found code");
         return;
     }
     while(1)
     {
         char cur = Code[it];
         int curit = it;
         switch (Code[it]) {
         //в зависимости от кода функции выбираем действие
         case CNVAR:
             it++;
             getname();
             add_var(string(NameVar));
             break;
         case CSVAR:
             it++;
             getname();
             set_var(NameVar, Data.pop());
             break;
         case CPUSH:
             it++;
             Data.push(*((double*)(Code+it)));
             it+=sizeof(double);
             break;
         case CMULT:
             mul();
             break;
         case CADD:
             add();
             break;
         case CSUB:
             sub();
             break;
         case CDIV:
             div();
             break;
         case CSQRT:
             sqrt();
             break;
         case COUT:
             print();
             break;
         case CHALT:
             return;
         default:
             error("Cann't understand command.");
             break;
         }
     }
 }
开发者ID:ivanprosh,项目名称:Lingvo,代码行数:54,代码来源:main.cpp

示例7: div

 //деление
 void div()
 {
     if(Data.size()>1)
     {
         double y = Data.pop();
         double x = Data.pop();
         if(y) Data.push(x/y);
         else error("devide by zero");
         it++;
     }
     else error("cann't execute add, stack is empty");
 }
开发者ID:ivanprosh,项目名称:Lingvo,代码行数:13,代码来源:main.cpp

示例8: findFirstIntersection

// Traverses ray through KDTree and intersects ray with all of the objects along
// the way. Returns the first intersecting object
// if there is one.
// Entry:
//   ray     - the ray being traced
//   KDTree - the KD tree enclosing the entire environment
// Exit:
//   obj      - the first object that intersects the ray
bool KDTree::findFirstIntersection( const TRay &ray, const float maxDist2,
				    TObject *&obj ) const {
  TStack *stack;
  BinNode *currentNode, 
    *nearChild, *farChild;
  float dist, _min, _max;
  TPoint3 p;

#ifdef __DEBUG__
  ray.origin.print("ray origin");
  ray.direction.print("ray direction");
  ray.reverseDirection.print("ray reverse direction");
#endif

  // test if the whole KD tree is missed by the input ray
  if ( !rayBoxIntersect(ray, min, max, _min, _max ) )
#ifdef __DEBUG__
    {
      printf("whole KD tree is missed by ray\n");
#endif
      return false;
#ifdef __DEBUG__
    }
#endif


#ifdef __DEBUG__
  printf("rayBoxIntersect: %5.5f   %5.5f\n", _min, _max );
#endif

  stack = new TStack;
  stack->init();

  currentNode = root;

  while ( currentNode != NULL ) {

    while ( !currentNode->leaf() ) {
#ifdef __DEBUG__
      currentNode->min.print("current node min"); currentNode->max.print("current node max");
      printf("is leaf: %d\n", currentNode->leaf() );
      currentNode->child[0]->max.print("cut plane");
#endif

      dist = currentNode->distanceToDivisionPlane( currentNode->child[0]->max, ray );
      currentNode->getChildren( currentNode, ray.origin, nearChild, farChild );

#ifdef __DEBUG__
      printf("distance to plane: %5.5f\n", dist );
      
      nearChild->min.print("near min"); nearChild->max.print("near max");
      printf("is near leaf: %d\n", nearChild->leaf() );
      farChild->min.print("far min"); farChild->max.print("far max");
      printf("is far leaf: %d\n", farChild->leaf() );
#endif

      if ( ( dist > _max ) || ( dist < 0 ) ) {
#ifdef __DEBUG__
	printf("using near child\n");
#endif
	currentNode = nearChild;
      }
      else if ( dist < _min ) {
#ifdef __DEBUG__
	printf("using far child\n");
#endif
	currentNode = farChild;
      }
      else {
	stack->push( farChild, dist, _max );
#ifdef __DEBUG__
	printf("-->PUSH far  keep near\n");
#endif
	currentNode = nearChild;
	_max = dist;
      }
    }

#ifdef __DEBUG__
    printf("rayObjIntersect:\n");
    currentNode->min.print("currentNode min");
    currentNode->max.print("currentNode max");
#endif
    if ( rayObjIntersect( ray, currentNode->members, maxDist2, obj ) )
      return true;
    stack->pop( currentNode, _min,_max );
#ifdef __DEBUG__
    printf("-->POP\n");
    if ( currentNode ) {
      currentNode->min.print("currentNode min"); currentNode->max.print("currentNode max");
      printf("is leaf: %d\n", currentNode->leaf() );
    }
//.........这里部分代码省略.........
开发者ID:SinaC,项目名称:OldRaytrace,代码行数:101,代码来源:kdtree.cpp

示例9: Clear

void CErrorStack::Clear()
{
    TStack *cStack = m_cErrors.get();
    while (cStack->size() > 1)
        cStack->pop();
}
开发者ID:kfazi,项目名称:Engine,代码行数:6,代码来源:errorstack.cpp

示例10: Pop

void CErrorStack::Pop()
{
    TStack *cStack = m_cErrors.get();
    if (cStack->size() > 1)
        cStack->pop();
}
开发者ID:kfazi,项目名称:Engine,代码行数:6,代码来源:errorstack.cpp

示例11: do_command

bool do_command(char command, TStack &numbers)
/*Pre: The first parameter specifies a valid calculator command
  Post: The command specified by the first parameter has been applied to the 
		stack of numbers given by the second parameter. A result of true is returned
		unless commnad == 'q'.*/
{
	stack_entry p,q;
	switch(command)
	{
	case '?':
		cout<<"Enter a real number:"<<flush;
		cin>>p;
		if(numbers.push(p) == overflow)
			cout<<"Warning: Stack full, lost number"<<endl;
		break;
	case '=':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else
			cout<<p<<endl;
		break;
	case '+':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else{
			numbers.pop();
			if(numbers.top(q) == underflow){
				cout<<"Stack has just one entry"<<endl;
				numbers.push(p);
			}
			else
			{
				numbers.pop();
				if(numbers.push(p+q) == overflow)
					cout<<"Warning: Stack full, lost result"<<endl;
			}
		}
		break;
	case '-':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else{
			numbers.pop();
			if(numbers.top(q) == underflow){
				cout<<"Stack has just one entry"<<endl;
				numbers.push(p);
			}
			else
			{
				numbers.pop();
				if(numbers.push(p-q) == overflow)
					cout<<"Warning: Stack full, lost result"<<endl;
			}
		}
		break;
	case '*':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else{
			numbers.pop();
			if(numbers.top(q) == underflow){
				cout<<"Stack has just one entry"<<endl;
				numbers.push(p);
			}
			else
			{
				numbers.pop();
				if(numbers.push(p*q) == overflow)
					cout<<"Warning: Stack full, lost result"<<endl;
			}
		}
		break;
		case '/':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else{
			numbers.pop();
			if(numbers.top(q) == underflow){
				cout<<"Stack has just one entry"<<endl;
				numbers.push(p);
			}
			else
			{
				numbers.pop();
				if(numbers.push(p/q) == overflow)
					cout<<"Warning: Stack full, lost result"<<endl;
			}
		}
		break;
		case 'q':
			cout<<"Calculation finished.\n";
			return false;
	}
	return true;
}
开发者ID:wty1990000,项目名称:TY_repository,代码行数:95,代码来源:reversePolish.cpp

示例12: main

int main(int argc, char** argv) {

    TStack<Figure> stack;
    int state = start;
    while (1)
    {
        switch (state)
        {
        case start:
        {
            Tips();
            cin >> state;
            break;
        }
        case add:
        {

            PrintLine();
            cout << "Which figure you want to add?" << endl;

            TipsForFirgurs();

            int fig = 0;
            cin >> fig;
            PrintStars();

            if (fig == 1)
            {
                stack.push(shared_ptr<Figure>(new Triangle(cin)));
                PrintStars();
                break;
            }
            if (fig == 2)
            {
                stack.push(shared_ptr<Figure>(new Quadro(cin)));
                PrintStars();
                break;
            }
            if (fig == 3)
            {
                stack.push(shared_ptr<Figure>(new Rectangle(cin)));
                PrintStars();
                break;
            }

            if (fig == 0)
            {
                state = start;
                PrintStars();
                break;
            }

            cout << "Wrong number" << endl;
            PrintStars();
            break;
        }

        case del:
        {
            PrintStars();
            stack.pop();
            PrintStars();
            state = start;
            break;
        }

        case print:
        {
            PrintStars();
            for (auto i : stack)
                i->Print();
            PrintStars();
            state = start;
            break;
        }

        case srt:
        {
            clock_t time;
            double duration;

            time = clock();

            cout << "Sort -------------" << endl;
            stack.sort();
            cout << "Done -------------" << endl;
            duration = (clock() - time) / (double)CLOCKS_PER_SEC;
            cout << "Time of sort: " << duration << endl;
            state = start;
            break;
        }

        case par_sort:
        {
            clock_t time;
            double duration;

            time = clock();

            cout << "Parallel Sort ----" << endl;
//.........这里部分代码省略.........
开发者ID:desoo40,项目名称:mai_labs,代码行数:101,代码来源:main.cpp


注:本文中的TStack::pop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。