empty [C++ Reference]
Keywords: stl,queue,empty
Date: 2008-10-14T15:42:07-0700

## empty

Syntax:

        #include <queue>
        bool empty() const;

The empty() function returns true if the queue has no elements, false otherwise.

For example, the following code uses empty() as the stopping condition on a while loop to clear a queue while displaying its contents:

       queue<int> q;
       for( int i = 0; i < 5; i++ ) {
         q.push(i);
       }
       while( !q.empty() ) {
         cout << q.front() << endl;
         q.pop();
       }

Related Topics: size