本文整理汇总了C++中Disk::displayQueue方法的典型用法代码示例。如果您正苦于以下问题:C++ Disk::displayQueue方法的具体用法?C++ Disk::displayQueue怎么用?C++ Disk::displayQueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Disk
的用法示例。
在下文中一共展示了Disk::displayQueue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shiftLeft
void shiftLeft(int start, int end, int diskCount, Queue<int> board[])
{
int onePeg = start - 1;
int otherPeg = end - 1;
int steps = 0;
double totalSteps = pow(2.0, (double)diskCount) - 1;
Disk test;
while(steps < totalSteps)
{
bool cases = (board[onePeg].isEmpty() || board[onePeg].peek() > board[otherPeg].peek()) ? true : false;
makeValidMove(board[onePeg], board[otherPeg]);
test.displayQueue(19, 20, board[0]);
test.displayQueue(19, 40, board[1]);
test.displayQueue(19, 60, board[2]);
delay_output(DELAY);
if(cases)
board[onePeg].prioritize(board[onePeg].seek(board[onePeg].size()-1));
else
board[otherPeg].prioritize(board[otherPeg].seek(board[otherPeg].size()-1));
onePeg = (onePeg == 2) ? 0 : onePeg + 1;
otherPeg = (otherPeg == 2) ? 0 : otherPeg + 1;
steps++;
test.displayQueue(19, 20, board[0]);
test.displayQueue(19, 40, board[1]);
test.displayQueue(19, 60, board[2]);
delay_output(DELAY);
}
}
示例2: main
int main(int argc, char *argv[])
{
int diskCount = getDiskCount();
int startPos = getStartPos();
int endPos = getEndPos(startPos);
Queue<int> peg1(diskCount);
Queue<int> peg2(diskCount);
Queue<int> peg3(diskCount);
switch(startPos)
{
case 1:
for(int i = 1; i <= diskCount; i++)
peg1.enqueue(i);
break;
case 2:
for(int i = 1; i <= diskCount; i++)
peg2.enqueue(i);
break;
case 3:
for(int i = 1; i <= diskCount; i++)
peg3.enqueue(i);
break;
default:
cout << "error in initializing startPeg. " << endl;
break;
}
Queue<int> board[3];
board[0] = peg1;
board[1] = peg2;
board[2] = peg3;
initialize();
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
Disk test;
test.displayQueue(19, 20, board[0]);
test.displayQueue(19, 40, board[1]);
test.displayQueue(19, 60, board[2]);
delay_output(DELAY);
int findGoal = (startPos == 3) ? 1 : startPos + 1;
cout << " 1 2 3" << endl;
if(diskCount%2) //case for odd number of disks
{
//shift in the same direction of peg
if(findGoal == endPos) //if end peg is on right
shiftRight(startPos, endPos, diskCount, board);
else
shiftLeft(startPos, endPos, diskCount, board);
}
else //case for even number of disks
{
//shift in opposite direction of peg
int otherPeg = findOtherPeg(startPos, endPos);
if(findGoal == endPos) //if end peg is on right
shiftLeft(startPos, otherPeg, diskCount, board);
else
shiftRight(startPos, otherPeg, diskCount, board);
}
system("PAUSE");
return EXIT_SUCCESS;
}