本文整理汇总了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;
}
示例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);
}
}
示例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())
{
//.........这里部分代码省略.........