• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TStack类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了TStack类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: Expand

void CStackTraceImpl::Expand(CStackTrace::TStack& stack)
{
    char** syms = backtrace_symbols(&m_Stack[0], m_Stack.size());
    for (size_t i = 0;  i < m_Stack.size();  ++i) {
        string sym = syms[i];

        CStackTrace::SStackFrameInfo info;
        info.func = sym.empty() ? "???" : sym;
        info.file = "???";
        info.offs = 0;
        info.line = 0;

        string::size_type pos = sym.find_first_of("(");
        if (pos != string::npos) {
            info.module = sym.substr(0, pos);
            sym.erase(0, pos + 1);
        }

        pos = sym.find_first_of(")");
        if (pos != string::npos) {
            sym.erase(pos);
            pos = sym.find_last_of("+");
            if (pos != string::npos) {
                string sub = sym.substr(pos + 1, sym.length() - pos);
                info.func = sym.substr(0, pos);
                info.offs = NStr::StringToInt(sub, 0, 16);
            }
        }

        //
        // name demangling
        //
        if ( !info.func.empty()  &&  info.func[0] == '_') {
#if NCBI_COMPILER_VERSION >= 310
            // use abi::__cxa_demangle
            size_t len = 0;
            char* buf = 0;
            int status = 0;
            buf = abi::__cxa_demangle(info.func.c_str(),
                                      buf, &len, &status);
            if ( !status ) {
                info.func = buf;
                free(buf);
            }
#endif
        }

        stack.push_back(info);
    }

    free(syms);
}
开发者ID:swuecho,项目名称:igblast,代码行数:52,代码来源:ncbi_stack_linux.cpp


示例3: main

int main() {
    srand(time(NULL)); // Seed random number generator
    TStack<Trash> bin; // Default to ownership
    // Fill up the Trash bin:
    for (int i = 0; i < 30; i++) {
        switch (rand() % 3) {
        case 0:
            bin.push(new Aluminum(rand() % 100));
            break;
        case 1:
            bin.push(new Paper(rand() % 100));
            break;
        case 2:
            bin.push(new Glass(rand() % 100));
            break;
        }

        // Bins to sort into:
        TStack<Trash> glassBin(0); // No ownership
        TStack<Trash> paperBin(0);
        TStack<Trash> alBin(0);
        TStackIterator<Trash> sorter(bin);

        // Sort the Trash:
        // (RTTI offers a nicer solution)
        while (sorter) {
            // Smart pointer call:
            switch(sorter->trashType()) {
            case AluminumT:
                alBin.push(sorter.current());
                break;
            case PaperT:
                paperBin.push(sorter.current());
                break;
            case GlassT:
                glassBin.push(sorter.current());
                break;
            }

            sorter++;
        }

        SumValue(alBin, out);
        SumValue(paperBin, out);
        SumValue(glassBin, out);
        SumValue(bin, out);

        return 0;
    }
} ///:~
开发者ID:jacob-zhoupeng,项目名称:thinkincpp,代码行数:50,代码来源:Recycle.cpp


示例4: main

int main() {
    TStack<Gromit> dogs;

    for (int i = 0; i < 5; i++) {
        dogs.push(new Gromit(i));
    }

    applist(dogs, &Gromit::speak, 1);
    applist(dogs, &Gromit::eat, 2.0f);
    applist(dogs, &Gromit::sleep, 'z', 3.0);
    applist(dogs, &Gromit::sit);

    return 0;
} ///:~
开发者ID:jacob-zhoupeng,项目名称:thinkincpp,代码行数:14,代码来源:Applist.cpp


示例5: main

int main() {
  TStack s;
  int i, n, m;
  
  do {
    printf("Digite um numero interio positivo : ");
    scanf("%d", &n);
  } while (n < 0); 
  
  m = n;

  while (n) {
    s.push(n % 2);
    n = n / 2;
  }
  
  printf("O numero %d na base2 eh :", m);
  s.print("");
  return 0;
}
开发者ID:marcosf63,项目名称:CC,代码行数:20,代码来源:l03q04.cpp


示例6: Pop

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


示例7: add_rigid_body

void add_rigid_body(OBJMESH *objmesh, float mass)
{
    /* Create a new Box collision shape for the current mesh. */
    /* Use half of the dimension XYZ to represent the extent of the box
     * relative to its pivot point, which is already centered in the middle of
     * its bounding box.
     */
    btCollisionShape *btcollisionshape = new btBoxShape(btVector3(objmesh->dimension->x * 0.5f,
                                                                  objmesh->dimension->y * 0.5f,
                                                                  objmesh->dimension->z * 0.5f));

    /* Declare a btTransform variable to be able to contain the transformation
     * matrix of the object in a form that Bullet will understand.
     */
    btTransform bttransform;

    TStack  l;
    l.loadTranslation(objmesh->location);
    // Convert angles to radians & divide by 2.
    float   alpha = objmesh->rotation->z*DEG_TO_RAD_DIV_2;
    float   cosAlpha(cosf(alpha)), sinAlpha(sinf(alpha));
    float   beta  = objmesh->rotation->y*DEG_TO_RAD_DIV_2;
    float   cosBeta(cosf(beta)), sinBeta(sinf(beta));
    float   gamma = objmesh->rotation->x*DEG_TO_RAD_DIV_2;
    float   cosGamma(cosf(gamma)), sinGamma(sinf(gamma));
    float   cAcB(cosAlpha*cosBeta);
    float   sAsB(sinAlpha*sinBeta);
    float   cAsB(cosAlpha*sinBeta);
    float   sAcB(sinAlpha*cosBeta);
    l.rotate(quaternion(cAcB*cosGamma+sAsB*sinGamma,
                        cAcB*sinGamma-sAsB*cosGamma,
                        cAsB*cosGamma+sAcB*sinGamma,
                        sAcB*cosGamma-cAsB*sinGamma));

    /* Assign the current transformation matrix that you create using the
     * standard "OpenGL way" and send it over to the Bullet transform variable.
     */
    bttransform.setFromOpenGLMatrix(l.back().m());

    /* Create a new motion state in order for Bullet to be able to
     * maintain and interpolate the object transformation.
     */
    btDefaultMotionState *btdefaultmotionstate = NULL;

    btdefaultmotionstate = new btDefaultMotionState(bttransform);

    /* Create a Bullet vector to be able to hold the local inertia of
     * the object.
     */
    btVector3 localinertia(0.0f, 0.0f, 0.0f);

    /* If a mass greater than 0 is passed in as a parameter to the function,
     * use it to calculate the local inertia.  If a mass is equal to 0, it means
     * that the object is static and you do not need to execute this calculation.
     */
    if (mass > 0.0f)
        btcollisionshape->calculateLocalInertia(mass, localinertia);

    /* Create a new rigid body and link the information that you have
     * calculated above.  Note that you are using the btRigidBody pointer already
     * contained in the OBJMESH structure to initialize the class.  This way, when
     * you're drawing, you can easily query the pointer in order to gain access to
     * its transformation matrix, which is from now on maintained by Bullet
     * internally.
     */
    objmesh->btrigidbody = new btRigidBody(mass,
                                           btdefaultmotionstate,
                                           btcollisionshape,
                                           localinertia);

    /* Built into the btRigidBody class is a "void *" variable that
     * allows you to associate a user-defined pointer with the rigid
     * body.  By associating the current objmesh pointer to this
     * variable, you will have direct access to the OBJMESH structure
     * at any time inside any Bullet-driven functions and callbacks.
     */
    objmesh->btrigidbody->setUserPointer(objmesh);

    /* Only mark the object named "Cube" to receive a contact-added callback. */
    if (!strcmp(objmesh->name, "Cube")) {
        /* Adjust the collision flags for this body by adding
         * CF_CUSTOM_MATERIAL_CALLBACK to the current flags.
         */
        objmesh->btrigidbody->setCollisionFlags(objmesh->btrigidbody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
    }

    /* Add the new rigid body to your physical world. */
    dynamicsworld->addRigidBody(objmesh->btrigidbody);
}
开发者ID:crlarsen,项目名称:gamelibrary,代码行数:89,代码来源:templateApp.cpp


示例8: printf

// 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: 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


示例10: Count

unsigned int CErrorStack::Count()
{
    TStack *cStack = m_cErrors.get();
    return cStack->size() - 1;
}
开发者ID:kfazi,项目名称:Engine,代码行数:5,代码来源:errorstack.cpp


示例11:

const CErrorStack::SError &CErrorStack::Check()
{
    TStack *cStack = m_cErrors.get();
    return cStack->top();
}
开发者ID:kfazi,项目名称:Engine,代码行数:5,代码来源:errorstack.cpp


示例12: Clear

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


示例13: 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


示例14: Push

void CErrorStack::Push(const CErrorStack::ECode eCode, const CString &cMessage)
{
    TStack *cStack = m_cErrors.get();
    cStack->push(SError(eCode, cMessage));
}
开发者ID:kfazi,项目名称:Engine,代码行数:5,代码来源:errorstack.cpp


示例15: 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


示例16: 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


示例17: 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


示例18: 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


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TStageObject类代码示例发布时间:2022-05-31
下一篇:
C++ TSqlORMapper类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap