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


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

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


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

示例1: isBipartite

    bool isBipartite() {
        int source;
        int* color = new int[num_of_vertices + 1];
        for (int i = 0; i <= num_of_vertices; ++i)color[i] = -1;
        while ((source = stillUncoloured(color, num_of_vertices + 1)) != 0) {
            color[source] = 0;
            Queue q;
            q.Enqueue(source);
            while (!q.isEmpty()) {
                int u = q.Dequeue();
                Node*p = g[u].head;
                while (p) {
                    if (color[p->x] == -1) {
                        color[p->x] = (color[u] == 0) ? 1 : 0;
                        q.Enqueue(p->x);
                    } else if (color[p->x] == color[u]) {
                        return false;
                    }
                    p = p->next;
                }
            }

        }
        delete [] color;
        return true;
    }
开发者ID:Sandy4321,项目名称:my-data-structures,代码行数:26,代码来源:Graph.cpp

示例2: 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)
{
/*
const int Open     = -1;	// Cell is open
const int Obstacle = -2;	// Cell is an obstacle
const int StartCell= -3;	// Cell is the start cell
const int GoalCell = -4;	// Cell is the goal cell
const int PathCell = -5;	// Cell is on the shortest path
*/ 
	Position curPos = maze.Start();
	Position neighbor;
	positionQueue.Enqueue(curPos);
	maze.Mark(curPos, 0);
	int distance;

	while(!positionQueue.Empty()){
		curPos = positionQueue.Dequeue();
		distance = maze.State(curPos);
		neighbor = openPosition(maze, curPos);
		while(curPos != neighbor){
			maze.Mark(neighbor, distance + 1);
			if(neighbor == maze.Goal())
				return true;
			positionQueue.Enqueue(neighbor);
			neighbor = openPosition(maze, curPos);
		}
	}
	return false;
}
开发者ID:jazzywhit,项目名称:Data-Structures,代码行数:42,代码来源:Prog6.cpp

示例3: main

// Just for testing.
int main(int argc, char* argv[]) {
  Queue<int> Q;
  Q.Enqueue(1);
  Q.Enqueue(2);
  assert(2 == Q.Max());
  assert(1 == Q.Dequeue());  // 1
  assert(2 == Q.Max());
  assert(2 == Q.Dequeue());  // 2
  Q.Enqueue(3);
  assert(3 == Q.Max());
  assert(3 == Q.Dequeue());  // 3
  try {
    Q.Max();
  }
  catch (const exception& e) {
    cout << e.what() << endl;  // throw
  }
  try {
    Q.Dequeue();
  }
  catch (const exception& e) {
    cout << e.what() << endl;  // throw
  }
  return 0;
}
开发者ID:Heuristack,项目名称:Productivity,代码行数:26,代码来源:Queue_with_max_using_deque.cpp

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

示例5: main

int main()
{
    //queue<char*> words;
    Queue<char*> words;
	//Kristian: Липсват подсказващи съобщения.
    int n;
    cin>>n;
    //81094: I would insert spaces around the operators for a better esthetical view.
	//Kristian: Решението определено не решава задачата. При аргумент 3 имаш повтарящи се поддуми. Пример: aaa.
	//Kristian: При аргумент 4, не се генерират всички възможни поддуми. Пример: липсва bbbb.Освен това, отново има повтарящи се: abcd.
    for(int i=1;i<=n;i++)
    {
        int* arr=new int[i];
        int symbol=(int)'a';
        for(int j=0;j<pow(3,i);j++)
        {
            IntToAnyNumSystem(j,n,arr,i);
            char* word=new char[i];
            for(int i1=0;i1<i;i1++)
                word[i1]=(char)(arr[i1]+symbol);
            word[i]='\0';
            words.Enqueue(word);
        }
        delete[] arr;
    }
    while(!words.Empty())
       printf ("%s \n", words.Dequeue());
    return 0;
}
开发者ID:smurfolan,项目名称:SDP-PCODE-REVIEW,代码行数:29,代码来源:main2.cpp

示例6: LevelOrders

void LevelOrders(Tree T){
	Queue<node_t> Q;
	node_t tmp = Root(T);
	while (Label(tmp,T) != ""){
		cout << Label(tmp,T);
		node_t child = Leftmost_Child(tmp,T);
		while (Right_Sibling(child,T) != 0){
			Q.Enqueue(child);
			child = Right_Sibling(child,T);
		}
		Q.Enqueue(child);
		tmp = Q.Front();
		Q.Dequeue();
	}

}
开发者ID:mayankgureja,项目名称:CS260-Data-Structures,代码行数:16,代码来源:LevelOrder.cpp

示例7: main

int main()
{
   Queue<int> line;                                  // Line-up waiting to get in

   int patrons = InitialPatrons;                     // Number people in the Inn

   int time, i, arrivals, departures, entry_time;

   Randomize();                                      // Seed the random numbers

   for (time=0; time<300; time++)                    // Each minute from 8 - 1.
   {
      arrivals = RandomNum(num_arrive[time/60]);     // arriving this minute

      for (i=0; i<arrivals; i++) line.Enqueue(time); // End of the line

      departures = RandomNum(num_depart[time/60]);   // leaving this minute

      patrons -= departures;                         // bye-bye

      while (patrons < Capacity && !line.Empty())
      {
         entry_time = line.Front();                  // move from line into Inn
         line.Dequeue();
         patrons++;
      }
      cout << setw(4) << time << ":  " << arrivals << "  " << departures
           << setw(5) << patrons << endl;
   }

   cout << setw(4) << time << ":  " << arrivals << "  " << departures
        << setw(5) << patrons << endl;

   return (0);
}
开发者ID:PatrickWalter1,项目名称:CbasedProjects,代码行数:35,代码来源:inn.cpp

示例8: main

int main()
{
    Queue<int, 3> Q;

    try
    {
        Q.Enqueue(1);
        Q.Enqueue(3);
        Q.Enqueue(4);
        while (!Q.Empty())
            std::printf("%d\n", Q.Dequeue());
    }
    catch (Queue<int, 3>::BadOp& e)
    {
        std::puts("Queue::BadOp caught!");
    }
}
开发者ID:Swagramming,项目名称:example,代码行数:17,代码来源:4f.cpp

示例9: main

int main()
{
    /*Driver Code to test the implementation
    Printing the elements in Queue after each Enqueue or Dequeue
    */
    Queue Q; // creating an instance of Queue.
    Q.Enqueue(2);
    Q.Print();
    Q.Enqueue(4);
    Q.Print();
    Q.Enqueue(6);
    Q.Print();
    Q.Dequeue();
    Q.Print();
    Q.Enqueue(8);
    Q.Print();
}
开发者ID:handong1587,项目名称:OJ,代码行数:17,代码来源:Queue.cpp

示例10: main

int main ()
{
	Queue Q;

	Q.Enqueue(1);
	Q.Enqueue(8);
	Q.Enqueue(2);
	Q.Enqueue(4);
	Q.Enqueue(9358);
	Q.Enqueue(56);
	Q.Enqueue(3);

	Q.dequeue();
	Q.dequeue();

	return 0;
}
开发者ID:asadzia,项目名称:Algorithms-and-Data-Structures,代码行数:17,代码来源:QueueWithStacks.cpp

示例11: testQueue

bool testQueue()
{
	Queue<int> myQ;
	myQ.Enqueue(1);
	myQ.Enqueue(2);
	myQ.Enqueue(3);

	assert(myQ.Front() == 1);

	myQ.Dequeue();
	assert(myQ.Front() == 2);

	Queue<int> myQcopy(myQ);
	assert(myQcopy.Front() == 2);
	myQcopy.Dequeue();
	assert(myQcopy.Front() == 3);

	return true;
}
开发者ID:tstaples,项目名称:VGP220,代码行数:19,代码来源:QueueTest.cpp

示例12: BFS

 int * BFS(int source) {
     int* dist = new int[num_of_vertices + 1];
     for (int i = 0; i <= num_of_vertices; ++i)dist[i] = -1;
     dist[source] = 0;
     Queue q;
     q.Enqueue(source);
     while (!q.isEmpty()) {
         int u = q.Dequeue();
         Node*p = g[u].head;
         while (p) {
             if (dist[p->x] == -1) {
                 dist[p->x] = dist[u] + 1;
                 q.Enqueue(p->x);
             }
             p = p->next;
         }
     }
     return dist;
 }
开发者ID:Sandy4321,项目名称:my-data-structures,代码行数:19,代码来源:Graph.cpp

示例13: ReadInput

void ReadInput( Queue &q)
{
	int input;
	int num;
	cout <<  "Hoe many record to be inserted : " << endl;
	cin >> num;
	for(int i=0;i<num;i++)
	{	
	    cin >> input;
		 q.Enqueue(input);
	}
}
开发者ID:sujeet05,项目名称:CLRS-Algorithms,代码行数:12,代码来源:Queue_Array.cpp

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

示例15: main

void main()
{
	Queue<Rechteck*> queue;

	queue.Enqueue(new Rechteck(3, 4));
	queue.Enqueue(new Rechteck(6, 7));

	while (queue.GetCount() > 0)
	{
		auto rechteck = queue.Dequeue();
		delete rechteck;
	}
}
开发者ID:feO2x,项目名称:PG2_SoSe_2015,代码行数:13,代码来源:main.cpp


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