本文整理汇总了C++中Queue::Dequeue方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::Dequeue方法的具体用法?C++ Queue::Dequeue怎么用?C++ Queue::Dequeue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::Dequeue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例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)
{
/*
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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
}
示例9: 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();
}
}
示例10: main
int main()
{
for (int i = 0; i < 10; i++)
{
q.Enqueue(i);
}
for (int i = 0; i < 10; i++)
{
cout << "Queue item: " << q.Peek() << endl; //Get the item to print
q.Dequeue(); // Removing the item from the queue
}
getchar();
return 0;
}
示例11: 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();
}
示例12: 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!");
}
}
示例13: 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;
}
示例14: 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;
}
示例15: main
int main(){
Queue q;
for(int i=0;i<9;i++){
q.Enqueue(i);
}
q.print();
std::cout << "front is : "<< q.Front() << std::endl;
for(int i=0;i<=10;i++){
q.Dequeue();
}
q.print();
std::cout << "front is : "<< q.Front() << std::endl;
return 0;
}