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


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

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


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

示例1: main

int main(int argc, char* argv[])
{
    bool ok;

    Queue queue;
    queue.EnQueue(1);
    queue.EnQueue(2);
    queue.EnQueue(3);


    // queue.ClearQueue();
    // queue.IsEmpty();


    while (!queue.IsEmpty())
    {
        cout << queue.DeQueue(ok) << endl;
    }

    queue.EnQueue(5);
    queue.EnQueue(6);

    while (!queue.IsEmpty())
    {
        cout << queue.DeQueue(ok) << endl;
    }

    return 0;
}
开发者ID:lssxfy123,项目名称:C-study,代码行数:29,代码来源:test.cpp

示例2: ModelSpread

bool Spread::ModelSpread(Queue<long> &lqueue,map<long,UserStatus> &userSMap)
{
    map<long,UserStatus>::iterator iter2;
    map<long,float> userSMapDcache;
    map<long,float>::iterator iter3;
    map<long int,UserLink>::iterator iter4;
    while(!lqueue.IsEmpty()){
            long userid = lqueue.GetQueue();
            iter4 = userGraphMap->find(userid);
            //免疫因子 /mu
            if(userSMap[userid].tfIdf<mu){
                      continue;
            }
            if(iter4 != userGraphMap->end())
            {
                UserLink head = iter4->second;
                float srcWeight = head->weight;
                float dstWeight;
                int connect;
                UserNode *g = head->next;
                while(g!=NULL){
                    iter2 = userSMap.find(g->uid);
                    if(iter2 == userSMap.end())
                    {
                        dstWeight = g->weight;
                        connect = g->connect;
                        float diffuseRate = DiffuseRate(srcWeight,dstWeight,connect);
                        float tfIdf = userSMap[userid].tfIdf;
                        iter3 = userSMapDcache.find(g->uid);
                        if(iter3 != userSMapDcache.end())
                            userSMapDcache[g->uid] += tfIdf*diffuseRate;
                        userSMapDcache[g->uid] = tfIdf*diffuseRate;
                    }
                    g = g->next;
                }
            }
            if(lqueue.IsEmpty())
            {
               for(iter3 = userSMapDcache.begin();iter3 != userSMapDcache.end();iter3++)
               {
                   lqueue.EnQueue(iter3->first);
                   UserStatus userStatus;
                   userStatus.infected =true;
                   userStatus.tfIdf = iter3->second;
                   userSMap[iter3->first] = userStatus;
               }
               userSMapDcache.clear();
            }
        }
    return true;
}
开发者ID:alongyin,项目名称:HotTopicPrediction,代码行数:51,代码来源:spread.cpp

示例3: menuQueue

void  menuQueue()
{
	Queue *queue = new Queue;
	char c;
	do
	{
		printf("1: Push\n");
		printf("2: Pop\n");
		printf("3: IsEmpty\n");
		printf("\nEsc: Exit\n");
		c = getch();
		switch(c)
		{
		case '1': 
			cout << "Push:";
			int val;
			cin >> val;
			queue->Push(val);
			cout << endl; break;
		case '2': 
			cout << "Pop:";
			int v;
			v = queue->Pop();
			cout << v << endl; break;
		case '3': 
			cout << "IsEmpty:";
			bool flag = queue->IsEmpty();
			cout << ( flag == true ? "true" : "false") << endl; break;
		}
	} while(c != 27);
	delete queue;
}
开发者ID:klyuchnikov,项目名称:LabsThreeSemestrsEVM,代码行数:32,代码来源:Main.cpp

示例4: main

int main()
{
    Queue<int> queue;
    queue.Enqueue(10);
    queue.Enqueue(20);
    cout<<queue.IsEmpty()<<endl;
    cout<<queue.IsFull()<<endl;
    cout<<queue.Front()<<endl;
    queue.Dequeue();
    cout<<queue.Front()<<endl;
    return 0;
}
开发者ID:Botrix,项目名称:DataStruct,代码行数:12,代码来源:main.cpp

示例5: 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();
}
开发者ID:3588,项目名称:au-cs230,代码行数:23,代码来源:8.cpp

示例6: main

int main(int argc, char** argv)
{
	// Stack test
	Stack<int> s;
	s.Push(10);
	s.Push(20);
	s.Push(30);
	s.Push(40);
	s.Push(1);
	s.Push(2);
	s.Push(3);
	s.Push(4);
	s.Push(5);
	s.Push(6);
	s.Push(7);
	s.Push(8);
	while(!s.IsEmpty())
	{
		printf("%d\n", s.Top());
		s.Pop();
	}
	printf("-----\n");
	
	// Queue test
	Queue<int> q;
	q.Enque(10);
	q.Enque(20);
	q.Enque(30);
	q.Enque(40);	
	q.Enque(1);
	q.Enque(2);
	q.Enque(3);
	q.Enque(4);
	q.Enque(5);
	q.Enque(6);
	q.Enque(7);
	q.Enque(8);
	while(!q.IsEmpty())
	{
		printf("%d\n", q.Front());
		q.Deque();
	}
	printf("-----\n");

	// Maze test
	path(argv[1]);
		
	return 0;
}
开发者ID:skenzhegulov,项目名称:UNIST_CSE,代码行数:49,代码来源:main.cpp

示例7: while

template<typename T>void BinaryTree<T>::WidthOrder(TNode<T> *Current){
    if(Current!=NULL){
        Queue<TNode<T>*> q;      // 队列
        q.EnQue(Current);
        TNode<T> * p;
        while(!q.IsEmpty()) {
            p = q.DeQue();   // 队首元素出队列
            cout<<p->info<<'\t';	          // 访问p结点
            if(p->lchild)
                q.EnQue(p->lchild);
            if(p->rchild)
                q.EnQue(p->rchild);
        }  						//后序访问根结点
    }
}
开发者ID:wtksyjpy,项目名称:C-Practise,代码行数:15,代码来源:main.cpp

示例8: main

int main(int argc, const char * argv[]) {
    // insert code here...
   	int i;
    Queue<char> que;                             //缺省为18元素队列,可用17
    char str1[]="abcdefghijklmnop";//17个元素,包括串结束符
    que.MakeEmpty();
    for(i=0;i<17;i++) que.EnQue(str1[i]);
    if(que.IsFull()) cout<<"队满";
    cout<<"共有元素:"<<que.Length()<<endl;
    for(i=0;i<17;i++) cout<<que.DeQue();           //先进先出
    cout<<endl;
    if(que.IsEmpty()) cout<<"队空";
    cout<<"共有元素:"<<que.Length()<<endl;
    return 0;
}
开发者ID:wtksyjpy,项目名称:C-Practise,代码行数:15,代码来源:main.cpp

示例9: 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

}
开发者ID:minhajuddin,项目名称:lees_router,代码行数:41,代码来源:router.cpp

示例10: main

int main(void){
    
    int N = 10;    

    // instantiate a Queue that stores integers
    //
    Queue<int> *q = new Queue<int>();
     
    for(int i=1; i < N; ++i)
        q->Enqueue(i); 
    q->PrintItems();
    if(q->IsEmpty()) cout << "Queue is empty\n";    

    // Access the front in the Queue
    //
    cout << "Front Item: " << q->Front() << endl;
    cout << "Removing Front Item\n";
    // Remove the front item in the Queue
    q->Dequeue();

    // Print the Items
    q->PrintItems();
    return 0;
}
开发者ID:nanotechnoloG,项目名称:Algorithms,代码行数:24,代码来源:test_queue.cpp

示例11: 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;
}
开发者ID:psachin,项目名称:MyPublic,代码行数:77,代码来源:wire.cpp

示例12: 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:
//.........这里部分代码省略.........
开发者ID:kevingyc,项目名称:Homework,代码行数:101,代码来源:496470516_2.cpp

示例13: OnDraw

void CMFC_CreatBinaryTreeView::OnDraw(CDC* /*pDC*/)
{
	CMFC_CreatBinaryTreeDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	// TODO:  在此处为本机数据添加绘制代码

	CreatBinaryTreeDlg dlg;	//创建对话框类对象
	dlg.DoModal();
	//CString转换为wchar_t*
	wchar_t *VLR = dlg.PreBinTree.GetBuffer();
	dlg.PreBinTree.ReleaseBuffer();
	wchar_t *LVR = dlg.MidBinTree.GetBuffer();
	dlg.MidBinTree.ReleaseBuffer();


	int N = dlg.PreBinTree.GetLength();	  //前序序列的长度,二叉树结点个数
	int len = dlg.MidBinTree.GetLength();	//中序序列的长度
	if (N != len)
	{
		INT_PTR Respon;
		Respon = MessageBox(_T("前序和中序序列输入错误,退出!"), _T("错误提示"), MB_OK | MB_ICONSTOP);
		return;
	}

	//将对话框中的输入数据传入创建二叉树的模板类的构造函数中构造二叉树
	CBinaryTree<wchar_t> BinTree(VLR, LVR, N);
	BinTreeNode<wchar_t> *Root = BinTree.GetRoot();		//获取二叉树的根结点
	int depth = BinTree.Depth(Root);	//二叉树的深度
	Queue<BinTreeNode<wchar_t>*, int, int> Q;	//添加队列,用来存储二叉树的结点,以及结点所显示位置的圆的圆心坐标

	//获取菜单文本的坐标
	CRect Re;
	this->GetWindowRect(Re);
	auto w = Re.Width();
	auto h = Re.Height();
	CClientDC Dc(this);	

	//结点的坐标分布
	int Height = 1;	//结点的高度每增加一层点,高度就加一
	int HeightLeft;	//左孩子结点的高度
	int HeightRight; //右孩子结点的高度
	int R = h / (4 * (depth + 1));	//圆的半径

	int Molecule = 1;	//圆心坐标的分子
	int Denominator;	//圆心坐标的分母
	int X0, Y0;		//包装结点数据的圆的圆心坐标
	int XA, YA, XD, YD;		//圆外接正方形的左上角和右下角端点的坐标
	int XE, YE, XF, YF;		//连接两个圆的线段的端点坐标,点E在点F的上方
	Q.EnQueue(Root, Molecule, Height);

	while (!Q.IsEmpty())
	{
		//将当前结点的相关数据弹出
		Q.DeQueue(Root, Molecule, Height);
		//圆心坐标
		Denominator = (int)pow(2, Height);
		X0 = w*Molecule / Denominator;		//圆心横坐标
		Y0 = h*Height / (depth + 1);		//圆心纵坐标
		
		//正方形的两端点的坐标
		XA = X0 - R;	//正方形左上角端点坐标
		YA = Y0 - R;
		XD = X0 + R;	//正方形右下角端点坐标
		YD = Y0 + R;
		//画圆
		Dc.Ellipse(XA, YA, XD, YD);

		//在圆心显示二叉树的根结点数据
		CString da;
		da += Root->data;   
		Dc.SetTextColor(RGB(255, 0, 0));	//设置输出文本颜色为红色
		Dc.TextOutW(X0, Y0, da);

		if (Root->LeftChild)
		{
			//如果有左孩子,就画左线段
			//线段的上端点坐标
			XE = (int)(X0 - R / sqrt(2));		//XO为当前结点的圆心横坐标
			YE = (int)(Y0 + R / sqrt(2));		//YO为当前结点的圆心纵坐标

			HeightLeft = Height + 1;	//高度加一
			Molecule = 2 * Molecule - 1;	//左为减,左子女的圆心横坐标的分子
			//线段的下端点坐标
			XF = w*Molecule / (2 * Denominator);
			YF = h*HeightLeft / (depth + 1) -R;		
			//画左线段
			Dc.MoveTo(CPoint(XE, YE));
			Dc.LineTo(CPoint(XF, YF));
			
			//将访问左子女所需要的数据压入队列
			Q.EnQueue(Root->LeftChild, Molecule, HeightLeft);
			Molecule = (Molecule + 1) / 2;	//将跟结点圆心的分子还原
		}
		if (Root->RightChild)
		{
			//如果有右孩子,就画右线段
			//线段的上端点坐标
			XE = (int)(X0 + R / sqrt(2));		//XO为当前结点的圆心横坐标
//.........这里部分代码省略.........
开发者ID:cugwangping,项目名称:wangping_project,代码行数:101,代码来源:MFC_CreatBinaryTreeView.cpp


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