本文整理汇总了C++中Queue::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::Add方法的具体用法?C++ Queue::Add怎么用?C++ Queue::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::Add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Next
char* LevelIterator::Next()
{
if (CurrentNode) {
char temp = CurrentNode->data;
if (CurrentNode->LeftChild) q.Add(CurrentNode->LeftChild);
if (CurrentNode->RightChild) q.Add(CurrentNode->RightChild);
CurrentNode = *q.Delete(CurrentNode);
return &temp;
}
return 0;
}
示例2: LevelOrder
void Tree::LevelOrder()
// Traverse the binary tree in level order
{
Queue<TreeNode*> q;
TreeNode *CurrentNode = root;
while (CurrentNode) {
cout << CurrentNode->data << endl;
if (CurrentNode->LeftChild) q.Add(CurrentNode->LeftChild);
if (CurrentNode->RightChild) q.Add(CurrentNode->RightChild);
CurrentNode = *q.Delete(CurrentNode);
}
}
示例3: main
/**
\func int main()
*/
int main()
{
int N, dat;
Queue queue;
char command[4];
cin >> N;
for (int i = 1; i <= N; i++) {
scanf("%s", &command);
switch (command[0]) {
case 'a':
scanf("%d", &dat);
queue.Add(dat);
break;
case 'g':
queue.Show();
break;
case 'd':
queue.Del();
break;
default:
break;
}
}
system("pause");
}
示例4: propagate
void Router::propagate(Coordinate *source, Coordinate *target){
int stepId = 0;
queue->Add(source);
visit(source, stepId);
Coordinate *current;
GridPoint currentGridPoint;
bool targetFound = false;
do{
//get the next node from queue
current = queue->Remove();
currentGridPoint = getGridPointAt(current);
stepId = currentGridPoint.StepId + 1;
//get neighbors of source
Coordinate *neighbors = current->GetNeighbors();
int i;
//if any of them is the target, stop,
for (i = 0; i < 4; i++) {
if(neighbors[i].Equals(target)){
visit(&neighbors[i], stepId);
targetFound = true;
break;
}
//add it to the queue if
//it is not out of bounds
//it is not visited
if(neighbors[i].InBound(rows, cols) && !isVisited(&neighbors[i])){
queue->Add(&neighbors[i]);
visit(&neighbors[i], stepId);
}
}
}while(!queue->IsEmpty() && !targetFound);
//else add them to the queue
//do the same with the rest of the elements in the queue until the target is
//reached
}
示例5: EnQueue
QUEUE_ERRORTYPE EnQueue(
fsl_osal_ptr hQHandle,
fsl_osal_ptr pMessage,
efsl_osal_bool bMaxPriority)
{
Queue *pQueue = NULL;
pQueue = (Queue*) hQHandle;
pQueue->Add(pMessage);
return QUEUE_SUCCESS;
}
示例6: Run
void Airport::Run(){
int pri;
airplane p;
for(nowtime=1;nowtime<=endtime;nowtime++){
cout<<"\nThe "<<nowtime<<" Minutes";
pri=PRand(expectland);
for(int i=1;i<=pri;i++){
p=*Newairplane(p,ARRIVE);
if(airland.IsFull())NoServe(p,ARRIVE);else {airland.Add(p);if(1!=airland.Size())cout<<" waiting on runway.";}
}
pri=PRand(expectfly);
for(int i1=1;i1<=pri;i1++){
p=*Newairplane(p,FLY);
if(airfly.IsFull())NoServe(p,FLY);else {airfly.Add(p);if(1!=airland.Size()+airfly.Size())cout<<" waiting on runway.";}
}
if(airland.IsEmpty())Freeplane();
if(!airland.IsEmpty()){p=*airland.Delete(p);Land(p,3);}
else if(!airfly.IsEmpty()){p=*airfly.Delete(p);Fly(p,3);}
}
GetCalculate();
}
示例7: FindPath
bool FindPath(Position start, Position finish,
int& PathLen, Position * &path)
{// Find a path from start to finish.
// Return true if successful, false if impossible.
// Throw NoMem exception if inadequate space.
if ((start.row == finish.row) &&
(start.col == finish.col))
{PathLen = 0; return true;} // start = finish
// initialize wall of blocks around grid
for (int i = 0; i <= m+1; i++) {
grid[0][i] = grid[m+1][i] = 1; // bottom & top
grid[i][0] = grid[i][m+1] = 1; // left & right
}
// initialize offsets
Position offset[4];
offset[0].row = 0; offset[0].col = 1; // right
offset[1].row = 1; offset[1].col = 0; // down
offset[2].row = 0; offset[2].col = -1; // left
offset[3].row = -1; offset[3].col = 0; // up
int NumOfNbrs = 4; // neighbors of a grid position
Position here, nbr;
here.row = start.row;
here.col = start.col;
grid[start.row][start.col] = 2; // block
// label reachable grid positions
Queue<Position> Q;
do
{// label neighbors of here
for (int i = 0; i < NumOfNbrs; i++)
{
nbr.row = here.row + offset[i].row;
nbr.col = here.col + offset[i].col;
if (grid[nbr.row][nbr.col] == 0)
{
// unlabeled nbr, label it
grid[nbr.row][nbr.col] = grid[here.row][here.col] + 1;
if ((nbr.row == finish.row) && (nbr.col == finish.col))
break; // done
Q.Add(nbr);
} // end of if
} // end of for
// have we reached finish?
if ((nbr.row == finish.row) &&
(nbr.col == finish.col)) break; // done
// finish not reached, can we move to a nbr?
if (Q.IsEmpty()) return false; // no path
here = Q.First();// get next position
Q.Delete();
} while(true);
// construct path
PathLen = grid[finish.row][finish.col] - 2;
path = new Position [PathLen];
// trace backwards from finish
here = finish;
for (int j = PathLen-1; j >= 0; j--) {
path[j] = here;
// find predecessor position
for (int i = 0; i < NumOfNbrs; i++) {
nbr.row = here.row + offset[i].row;
nbr.col = here.col + offset[i].col;
if (grid[nbr.row][nbr.col] == j+2) break;
}
here = nbr; // move to predecessor
}
return true;
}
示例8: main
int main(void)
{
int *data; // 用來接收一副牌的資料
int times = 1,total = 0;
int faceu[SIZE][7] = {0}; // 7 plies of face-up cards
Queue stockcards; // storage facedown stock cards
Stack wastecards; // storage face-up waste plie cards
Stack faced[7]; // 7 piles of facedown cards
int Spade, Heart, Diamond, Club; // output plies
Number num[7] = {0}; // record faceu's status
while(times <= 100)
{
int i = 0, j = 0, k = 0, action = 0; // counter, action是動作計數器
int counter = 0; // 判斷步驟用的變數
int score = -52; // 分數
Club = Diamond = Heart = Spade = 0; // output plies initial
data = new_set_of_cards(times); // 要一副洗好的牌資料 , times為100次中的第幾次
for(i = 1; i <= 28 ;) // 發牌到下面七個row裡
{
for(j = k; j < 7; j++ ,i++)
{
faced[j].Push(data[i-1]);
num[j].fst = num[j].nth = (data[i-1] - 1) % 13;
num[j].fstcardno = num[j].cardno = data[i-1];
}
k++;
}
for(i = 28 ; i < 52 ; i++) // 發剩下的牌到牌堆裡
{
stockcards.Add(data[i]);
}
for(i = 0 ; i < 7 ; i++) // 翻開playing plie最下面的牌
{
faceu[0][i] = faced[i].Pop();
num[i].sheets = 1;
}
wastecards.Push(stockcards.Delete()); // 從牌堆翻一張牌到waste plie
while(counter == 0)
{
counter = 1;
//(a)從wasteplie和playing plie把最上方的牌移至output區 ( counter = 1 )
// 如果wasteplie空了,就從牌堆翻開一張牌放到wasteplie
/*-------------------------------------------------------------------------------------------------------*/
while(counter == 1)
{ /*----------wastecards part----------*/
if((wastecards.Top() - 1) == (13 * 0) + Spade ||(wastecards.Top() - 1) == (13 * 1) + Heart
||(wastecards.Top() - 1) == (13 * 2) + Diamond ||(wastecards.Top() - 1) == (13 * 3) + Club)
{/*----------可以放上去的狀況---------*/
score += 5;
switch((wastecards.Top() - 1) / 13)
{
case 0:
Spade++;
break;
case 1:
Heart++;
break;
case 2:
Diamond++;
break;
case 3:
Club++;
break;
}
wastecards.Pop();
action++;
if(wastecards.IsEmpty())
{
wastecards.Push(stockcards.Delete());
}
counter = 0;
break;
}
/*------playing plies part-------*/
for(i = 0 ; i < 7 ; i++)
{
if((num[i].cardno - 1) == (13 * 0) + Spade || (num[i].cardno - 1) == (13 * 1) + Heart
|| (num[i].cardno - 1) == (13 * 2) + Diamond || (num[i].cardno - 1) == (13 * 3) + Club)
{/*-------可以放上去的狀況-------*/
score += 5;
switch((num[i].cardno - 1) / 13)
{
case 0:
Spade++;
break;
case 1:
Heart++;
break;
case 2:
Diamond++;
break;
case 3:
//.........这里部分代码省略.........