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


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

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


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

示例1: main

int main()
{
    int choice = 0, numToAdd = 0, temp = 0;
    Queue QueueNode;
    
    do
    {
        // diplay menu of choices for user
        menu();
        
        // get and validate user's choice
        choice = user_selection();
        
        if (choice == 1)
        {
            cout << "Enter value to add to end of queue: ";
            
            // get and validate user's input
            numToAdd = validate();
            
            // Add number to the back of the queue
            QueueNode.addBack(numToAdd);
        }
        
        else if (choice == 2)
        {
            // remove value at front of queue w/o deleting node
            QueueNode.removeFront();
        }
        
        else if (choice == 3)
        {
            temp = QueueNode.getFront();
            
            while (temp != -1)
            {
                cout << temp << " ";
                
                QueueNode.removeFront();
                
                temp = QueueNode.getFront();
            }
        }
        
    } while (choice != 4);

    
    return 0;
}
开发者ID:jasoncearley,项目名称:CS162,代码行数:49,代码来源:main.cpp

示例2: userSelection

/*********************************************************************
** Function: userSelection
** Description: Sets rosters for both players
** Parameters: valid pointer to queue
** Pre-Conditions: valid pointer to queue
** Post-Conditions: queue with characters as assigned by player
*********************************************************************/
void userSelection(int rosterNum, Queue &queIn, int team){
	character *fighter = NULL;
	//string used to hold user selection
	string fighterChoice = "";
	int choice = 0;
	string name;

	for (int i = 0; i < rosterNum; i++){
		cout << "Fighter " << i + 1 << endl;
		cout << "1. Goblin 2. Reptile 3. Barbarian 4. Shadow 5. Blue Man" << endl;
		do{
			fighterChoice = getInput();
			choice = atoi(fighterChoice.c_str());
			if (choice > 5 || choice < 1) fighterChoice = "";
		} while (fighterChoice == "");

		//Create the first character object
		fighter = setFighters(choice);
		
		do{
			cout << "Character name (cannot be blank, cannot start with a space): ";
			getline(cin, name);
			if (name.size() > 0){
				if (name.at(0) == ' '){
					cout << "Name cannot begin with a space. Please reenter." << endl;
					name = "";
				}
			}
		} while (name == "");
		fighter->setFightName(name);
		fighter->setTeamNum(team);

		queIn.addBack(fighter);
	}

}
开发者ID:PrestonFrom,项目名称:MonsterFight,代码行数:43,代码来源:fightFuncs.cpp

示例3: main

int main(int argc, char * argv[])
{
    // Parse command line rguments
    customArgParser::InitalizeArguments();
    argp_parse (&customArgParser::argp, argc, argv, 0, 0, &customArgParser::arguments);

    DebugConsole::debug_print (0, true, COLOR_GREEN, "CS_162 lab_fb automated testing.\n\n");

    if (customArgParser::arguments.debugEnable == true)
    {
      DebugConsole::SetDebugLevel (1);
    }

    DebugConsole::debug_print (0, true, COLOR_WHITE, "Starting Automated tests...\n");

    // Create a stack and a queue

    Queue * myQueue = new Queue;
    Stack * myStack = new Stack;

    // Test functions on empty stack/queue
    // Check for segment violation

    myQueue->getFront();
    myQueue->removeFront();
    
    myStack->peek();
    myStack->pop();

    // Populate data

    myStack->push (1);
    myStack->push (2);
    myStack->push (3);

    // This should pop the number 3

    DebugConsole::debug_print (0, true, COLOR_WHITE, "stack pop: %d\n", myStack->peek());
    myStack->pop();

    // push more data

    myStack->push (4);
    myStack->push (5);

    // Print all data, empty stack

    while (!myStack->isEmpty())
    {
      DebugConsole::debug_print (0, true, COLOR_WHITE, "stack pop: %d\n", myStack->peek());
      myStack->pop();
    }

    // Push more items onto stack

    myStack->push (6);
    myStack->push (7);
    myStack->push (8);
    
    // Add items to the queue

    myQueue->addBack(1);
    myQueue->addBack(2);
    myQueue->addBack(3);

    // Get the first item from the queue and remove the first one

    DebugConsole::debug_print (0, true, COLOR_WHITE, "queue getFront: %d\n", myQueue->getFront());
    myQueue->removeFront();

    // Add more items to the queue

    myQueue->addBack(4);
    myQueue->addBack(5);

    // Print all queue items
    // Empty the queue

    while (!myQueue->isEmpty())
    {
      DebugConsole::debug_print (0, true, COLOR_WHITE, "queue getFront: %d\n", myQueue->getFront());
      myQueue->removeFront();
    }

    // Add new items to an empty queue

    myQueue->addBack(6);
    myQueue->addBack(7);
    myQueue->addBack(8);

    // Print all items from queue and stack
    // Remove all stack/queue items.

    while (!myStack->isEmpty())
    {
      DebugConsole::debug_print (0, true, COLOR_WHITE, "stack pop: %d\n", myStack->peek());
      myStack->pop();
    }
    while (!myQueue->isEmpty())
    {
//.........这里部分代码省略.........
开发者ID:jeremy-prater,项目名称:OSU,代码行数:101,代码来源:lab_fb_test.cpp


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