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


C++ Queue::AddQ方法代码示例

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


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

示例1: main

int main()
{
    Stack S;
    Queue Q;
    
    // insert values 10, 20, 30, 40 and 50 onto the stack
    for(int x = 1; x<=5; x++){
        int n = x*10;
        S.push(n);
        Q.AddQ(n);
    }
    
    
    //Display the content of the stack and queue to the screen
    std::cout<<"Contents of Stack"<<std::endl;
    S.display();
    std::cout<<endl<<std::endl;
    std::cout<<"Contents of Queue"<<std::endl;
    Q.display();
    std::cout<<endl<<std::endl;
    

    //Remove and display each value on the stack
    std::cout<<"Removing values from Stack"<<std::endl;
    while (!S.empty())
    {    int x;
        S.Top(x);
        std::cout<<std::endl;
        std::cout<<"Popping --- "<<x<<endl;
        S.pop();
        S.display();
    }
    
    if (S.empty())
        std::cout<<"Stack is empty."<<std::endl;
    
    
    //Remove and display each values on the Queue
    std::cout<<"Removing values from Queue"<<std::endl;
    while (!Q.empty())
    {    int x;
        Q.Front(x);
        std::cout<<std::endl;
        std::cout<<"Removing --- "<<x<<endl;
        Q.RemoveQ();
        Q.display();
    }
    
    if (Q.empty())
        std::cout<<"Queue is empty."<<std::endl;
}
开发者ID:ccannon94,项目名称:ncat-comp280-repository,代码行数:51,代码来源:main.cpp

示例2: ThreadFunc

int ThreadFunc(void * unused){
    int old_time,cur_time,x,y;
    old_time = cur_time = SDL_GetTicks();
    while( !gameOver ){
        while( alive ){
            while( !Operation.isEmpty() && alive){
                EnterCriticalSection(&cs);
                Operation.DeleteQ(command);
                curblk.ClearCube();
                switch( command ){
                    case MOVEDOWN: curblk.MoveDown();
                                   break;
                    case MOVELEFT: curblk.MoveLeft();
                                   break;
                    case MOVERIGHT:curblk.MoveRight();
                                   break;
                    case ROTATE  : curblk.Rotate();
                                   break;
                 }
                 if( command == TURNNEXT ){                 //有的特殊命令最好特殊处理
                    curblk.TurnNext();
                    break;
                 }
                 curblk.DrawCube();
                 Screen.flip();
                 LeaveCriticalSection(&cs);
            }
            cur_time = SDL_GetTicks();
            SDL_Delay(1);
            if( !AIMode ){
                if( cur_time - old_time < 500 ) continue;
                old_time = cur_time;
                Operation.AddQ(MOVEDOWN);
            }else{
                if( cur_time - old_time < 50 ) continue;
                old_time = cur_time;
                x = curblk.x;
                y = curblk.y;
                if( BestRotate>0 ){
                    Operation.AddQ(ROTATE);
                    BestRotate -= 1;
                    continue;
                }
                if( BestPath[x][y+1] ){
                    Operation.AddQ(MOVEDOWN);
                    BestPath[x][y+1] = 0;
                    y += 1;
                    continue;
                }else if( BestPath[x+1][y] ){
                    Operation.AddQ(MOVERIGHT);
                    BestPath[x+1][y] = 0;
                    x += 1;
                    continue;
                }else if( BestPath[x-1][y] ){
                    Operation.AddQ(MOVELEFT);
                    BestPath[x-1][y] = 0;
                    x -= 1;
                    continue;
                }
                alive = 0;
            }
        }
        while(DelLine());
        Operation.ClearQ();
        ShowCube();
        ShowScore();
        if( AIMode ) Search();
        alive = 1;
    }
    return 0;
}
开发者ID:375670450,项目名称:SDL-Tetries,代码行数:71,代码来源:SDL+Tetries_AIPlayer.cpp


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