cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : queue : push
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
queue
comparison operators
queue::queue
member functions:
· queue::back
· queue::empty
· queue::front
· queue::pop
· queue::push
· queue::size

-

queue::push public member function
void push ( const T& x );

Insert element

Adds a new element at the end of the queue, after its current last element. The content of this new element is initialized to a copy of x.

This member function effectively calls the member function push_back of the underlying container object.

Parameters

x
Value to be copied to the new element.
T is the first template parameter (the type of the elements stored in the queue).

Return value

none

Example

// queue::push/pop
#include <iostream>
#include <queue>
using namespace std;

int main ()
{
  queue<int> myqueue;
  int myint;

  cout << "Please enter some integers (enter 0 to end):\n";

  do {
    cin >> myint;
    myqueue.push (myint);
  } while (myint);

  cout << "myqueue contains: ";
  while (!myqueue.empty())
  {
    cout << " " << myqueue.front();
    myqueue.pop();
  }

  return 0;
}
The example uses push to add a new elements to the queue, which are then popped out in the same order.

Complexity

Constant.

See also

queue::pop Delete next element (public member function)
queue::size Return size (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us