本文整理汇总了C++中Queue::Front方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::Front方法的具体用法?C++ Queue::Front怎么用?C++ Queue::Front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::Front方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
Queue<int> q;
q.Push(1);
q.Push(2);
q.Push(3);
int h=q.Front();
cout<<h<<endl;
h=q.Front();
cout<<h<<endl;
}
示例2: 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;
}
示例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: 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;
}
示例5: 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;
}
示例6: main
int main()
{
Stack S;
Queue Q;
// insert values 10, 20, 30, 40 and 50 onto the stack
for(int x = 1; x<=5; x++){
int n = x*10;
S.push(n);
Q.AddQ(n);
}
//Display the content of the stack and queue to the screen
std::cout<<"Contents of Stack"<<std::endl;
S.display();
std::cout<<endl<<std::endl;
std::cout<<"Contents of Queue"<<std::endl;
Q.display();
std::cout<<endl<<std::endl;
//Remove and display each value on the stack
std::cout<<"Removing values from Stack"<<std::endl;
while (!S.empty())
{ int x;
S.Top(x);
std::cout<<std::endl;
std::cout<<"Popping --- "<<x<<endl;
S.pop();
S.display();
}
if (S.empty())
std::cout<<"Stack is empty."<<std::endl;
//Remove and display each values on the Queue
std::cout<<"Removing values from Queue"<<std::endl;
while (!Q.empty())
{ int x;
Q.Front(x);
std::cout<<std::endl;
std::cout<<"Removing --- "<<x<<endl;
Q.RemoveQ();
Q.display();
}
if (Q.empty())
std::cout<<"Queue is empty."<<std::endl;
}
示例7: 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;
}
示例8: 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();
}
}
示例9: Test
void Test()
{
Queue<int> q;
q.Push(1);
q.Push(2);
q.Push(3);
q.Push(4);
cout<<q.Front()<<endl<<endl;
cout<<q.Back()<<endl<<endl;
cout<<q.Empty()<<endl<<endl;
cout<<q.Size()<<endl<<endl;
q.Pop();
q.Pop();
q.Pop();
q.Pop();
q.Pop();
cout<<endl<<q.Empty()<<endl<<endl;
}
示例10: BFS
void Matrix::BFS(Point start, int rows, int cols, LinkedList<Point>& path)
{
if (matrix[start.getX()][start.getY()] == '#')
{
cout << "The position is invalid!\n";
return;
}
int dr[] = { 0, -1, 0, 1 };
int dc[] = { -1, 0, 1, 0 };
Queue<Point> queue;
queue.Enqueue(start);
matrix[start.getX()][start.getY()] = '?';
cout << "Starting from point: ";
cout << "(" << start.getX() << ", " << start.getY() << ")" << " : " << endl;
while (!queue.isEmpty())
{
start = queue.Front();
queue.Dequeue();
for (int d = 0; d < 4; d++)
{
Point nextPos(start.getX() + dr[d], start.getY() + dc[d]);
if (canPass(rows, cols, nextPos))
{
path.Push_Back(nextPos);
queue.Enqueue(nextPos);
matrix[nextPos.getX()][nextPos.getY()] = '?';
}
}
}
}
示例11: 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;
}
示例12: main
int main()
{
Queue<string> myStringQueue;
myStringQueue.Push( "Hello" );
myStringQueue.Push( "Saluton" );
myStringQueue.Push( "Konnichiwa" );
myStringQueue.Push( "Bonjour" );
myStringQueue.Push( "Hola" );
Stack<string> myStringStack;
myStringStack.Push( "Hello" );
myStringStack.Push( "Saluton" );
myStringStack.Push( "Konnichiwa" );
myStringStack.Push( "Bonjour" );
myStringStack.Push( "Hola" );
int count = 0;
while ( myStringStack.GetSize() != 0 )
{
cout << "Loop " << count << endl;
cout << "\t Stack: " << myStringStack.Top() << endl;
cout << "\t Queue: " << myStringQueue.Front() << endl;
cout << endl;
count++;
myStringStack.Pop();
myStringQueue.Pop();
}
cout << "Press a key to continue..." << endl;
cin.get();
Queue<int> myIntQueue;
myIntQueue.Push( 1 );
myIntQueue.Push( 1 );
myIntQueue.Push( 2 );
myIntQueue.Push( 3 );
myIntQueue.Push( 5 );
Stack<int> myIntStack;
myIntStack.Push( 1 );
myIntStack.Push( 1 );
myIntStack.Push( 2 );
myIntStack.Push( 3 );
myIntStack.Push( 5 );
count = 0;
while ( myIntStack.GetSize() != 0 )
{
cout << "Loop " << count << endl;
cout << "\t Stack: " << myIntStack.Top() << endl;
cout << "\t Queue: " << myIntQueue.Front() << endl;
cout << endl;
count++;
myIntStack.Pop();
myIntQueue.Pop();
}
cout << "Press a key to exit..." << endl;
cin.get();
return 0;
}
示例13: QueueTest
void QueueTest()
{
Queue<int> aqueue;
cout << "Testing isEmpty(): " << aqueue.isEmpty() << endl;
cout << "Testing Enqueue()" << endl;
for (int i = 0; i < 10; i++)
{
try
{
aqueue.Enqueue(i);
}
catch (Exception & except)
{
cout << except << endl;
}
}
cout << "Testing isEmpty(): " << aqueue.isEmpty() << endl;
cout << endl << "Testing Dequeue()" << endl;
for (int i = aqueue.Size(); i >= 0; i--)
{
try
{
aqueue.Dequeue();
}
catch (Exception & except)
{
cout << except << endl;
}
cout << aqueue.Size() << endl;
}
for (int i = 0; i < 10; i++)
{
aqueue.Enqueue(i);
cout << aqueue.Front() << endl;
}
cout << endl << "Testing copy constructor" << endl;
Queue<int> bqueue = aqueue;
cout << endl << "BSIZE " << bqueue.Size() << endl << endl;
for (int i = bqueue.Size(); i > 4; i--)
{
cout << bqueue.Dequeue() << endl;
}
cout << endl << "Testing assignment operator" << endl;
aqueue = bqueue;
cout << "Testing isEmpty(): " << aqueue.isEmpty() << endl;
for (int i = aqueue.Size(); i > 0; i--)
{
cout << aqueue.Dequeue() << endl;
}
cout << "Testing the ability to manipulate data at the front of the queue" << endl;
aqueue.Enqueue(99);
int &num = aqueue.Front();
cout << "The value stored at the front of the queue is: " << num << endl;
num = num + 1;
cout << "The value stored at the front of the queue is now: " << aqueue.Front() << endl;
}