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


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

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


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

示例1: WriteOutgoingData

static status_t WriteOutgoingData(const String & desc, DataIO & writeIO, const SocketMultiplexer & multiplexer, Queue<ByteBufferRef> & outQ, uint32 & writeIdx)
{
   if (multiplexer.IsSocketReadyForWrite(writeIO.GetWriteSelectSocket().GetFileDescriptor()))
   {
      while(outQ.HasItems())
      {
         ByteBufferRef & firstBuf = outQ.Head();
         uint32 bufSize = firstBuf()->GetNumBytes();
         if (writeIdx >= bufSize) 
         {
            outQ.RemoveHead();
            writeIdx = 0;
         }
         else
         {
            int32 ret = writeIO.Write(firstBuf()->GetBuffer()+writeIdx, firstBuf()->GetNumBytes()-writeIdx);
            if (ret > 0)
            {
               writeIO.FlushOutput();
               LogTime(MUSCLE_LOG_TRACE, "Wrote " INT32_FORMAT_SPEC " bytes to %s:\n", ret, desc());
               LogHexBytes(MUSCLE_LOG_TRACE, firstBuf()->GetBuffer()+writeIdx, ret);
               writeIdx += ret;
            }
            else if (ret < 0) LogTime(MUSCLE_LOG_ERROR, "Error, writeIO.Write() returned %i\n", ret);
         }
      }
   }
   return B_NO_ERROR;
}
开发者ID:ruurdadema,项目名称:muscle,代码行数:29,代码来源:udpproxy.cpp

示例2: main

int main()
{
	Queue Q;

	for(int i = 0; i < 10; ++i)
	{
		int* p = new int(i);
		Q.EnQueue(p);
		cout << "Size = " << Q.Size() << endl;
	}

	for(QueueNode* node = Q.Head(); node != 0; node = node->next)
	{
		int* p =(int*)node->data;
		cout << *p<< " ";
	}
	cout << endl;


	while(Q.Empty() == false)
	{
		int* p = (int*)Q.DeQueue();
		cout << *p << " ";
		cout << "Size = " << Q.Size() << endl;
		
	}
	cout << endl;
	return 0;
}
开发者ID:mobinsheng,项目名称:algorithm,代码行数:29,代码来源:main.cpp

示例3: SolveMaze

/*----- S o l v e M a z e (  ) ------------------------------

PURPOSE
Attempt to find the shortest path through the maze.

INPUT PARAMETERS
maze           -- the maze object to be traversed
positionQueue  -- the queue of current and future positions

RETURN VALUE
true  -- a path was found.
false -- failed to find a path.
-------------------------------------------------------------*/
bool SolveMaze(Maze &maze, Queue &positionQueue)
{
	maze.Mark(maze.Start(), 0);					// Mark the maze start with distance 0
	positionQueue.Enqueue(maze.Start());		// Add maze start to queue
	CellState distance = 0;						// cell distance from start

	while (!positionQueue.Empty())
	{
		while (((maze.State(positionQueue.Head() + StepEast)) == Open)			// While head position has any unmarked neighbors
			|| ((maze.State(positionQueue.Head() + StepSouth)) == Open) 
			|| ((maze.State(positionQueue.Head() + StepWest)) == Open) 
			|| ((maze.State(positionQueue.Head() + StepNorth)) == Open)) 	
		{
			distance = maze.State(positionQueue.Head());										// Set distance

			if ((maze.State(positionQueue.Head() + StepEast)) == Open)							// Is east cell open?
			{
				maze.Mark(positionQueue.Head() + StepEast, distance + 1);						// Mark cell with proper distance
				if ((positionQueue.Head() + StepEast) == maze.Goal())							// Is open cell the goal?
					return true;
				
				positionQueue.Enqueue(positionQueue.Head() + StepEast);							// Add it to the queue
			}
			else if ((maze.State(positionQueue.Head() + StepSouth)) == Open)					// Is south cell open?
			{
				maze.Mark(positionQueue.Head() + StepSouth, distance + 1);						// Mark cell with proper distance
				if ((positionQueue.Head() + StepSouth) == maze.Goal())							// Is open cell the goal?
					return true;
				
				positionQueue.Enqueue(positionQueue.Head() + StepSouth);						// Add it to the queue
			}
			else if ((maze.State(positionQueue.Head() + StepWest)) == Open)						// Is West cell open?
			{
				maze.Mark(positionQueue.Head() + StepWest, distance + 1);						// Mark cell with proper distance
				if ((positionQueue.Head() + StepWest) == maze.Goal())							// Is open cell the goal?
					return true;
				
				positionQueue.Enqueue(positionQueue.Head() + StepWest);							// Add it to the queue
			}
			else if ((maze.State(positionQueue.Head() + StepNorth)) == Open)					// Is North cell open?
			{
				maze.Mark(positionQueue.Head() + StepNorth, distance + 1);						// Mark cell with proper distance
				if ((positionQueue.Head() + StepNorth) == maze.Goal())							// Is open cell the goal?
					return true;
				
				positionQueue.Enqueue(positionQueue.Head() + StepNorth);						// Add it to the queue
			}
		}
		positionQueue.Dequeue();
	}
	return false;
}
开发者ID:WorldWideWebster,项目名称:Data-Structures,代码行数:65,代码来源:Prog7.cpp


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