Saturday, October 26, 2013

C++ (intermediate) STL queue

One of the most important classes in C++ STL( standard template library) is queue. Queue is a dynamic array. You can add elements from the back of the queue and remove elements from the beginning of the queue. The functions are called push and pop. Push stands for pushing an element from the back of the queue and pop stands for popping (taking out) the element from the beginning of the queue.





Queue is being defined like this
queue< data type> name_of_the_queue;

Here is the list of functions of queue.

push
is written like this q.push(a);
This command will add element a to the end of our queue. 

pop
   is written like this q,pop();
  This function has no parameters. It is just removing the first element of our queue.

front
 is written like this a=q,front();
this function is not a void type function it returns the value of the first element (returns not removes).

empty
is written like this q.empty(); 
This is a boolean function. It returns one of 2 values. It returns "true" if the queue is completely empty(no elements are present in the queue) and it returns "false" if there is at least one element present in the queue.

IF YOU HAVE ANY QUESTIONS LEAVE THEM IN COMMENTS. NO QUESTION WILL BE UNANSWERED

2 comments:

  1. This is great. I was curious about queues. It looks like they're similar to vectors.

    ReplyDelete
  2. Can you please include some demonstration examples to make this post more clear ?

    ReplyDelete