Module: Essential Tools Module Group: Traditional Collection Classes
Does not inherit
#include <rw/tqueue.h> RWTQueue<T, C> queue;
This class represents a parameterized queue. Not only can the type of object inserted into the queue be parameterized, but also the implementation.
Parameter T represents the type of object in the queue, either a class or built-in type. The class T must have:
well-defined copy semantics (T::T(const T&) or equivalent);
well-defined assignment semantics (T::operator=(const T&) or equivalent);
any other semantics required by class C.
Parameter C represents the class used for implementation. Useful choices are RWTValSlist<T,A> or RWTValDlist<T,A>. Vectors, such as RWTValOrderedVector<T,A>, can also be used, but tend to be less efficient at removing an object from the front of the list.
None
In this example a queue of RWCStrings, implemented as a singly-linked list, is exercised.
#include <iostream> #include <rw/tqueue.h> #include <rw/cstring.h> #include <rw/tvslist.h> int main() { RWTQueue<RWCString, RWTValSlist<RWCString> > q; q.insert("one"); // Type conversion occurs q.insert("two"); q.insert("three"); while (!q.isEmpty()) std::cout << q.get() << std::endl; return 0; }
Program output:
one two three
void clear();
Removes all items from the queue.
size_t entries() const;
Returns the number of items in the queue.
T first() const;
Returns, but does not remove, the first item in the queue (the item least recently inserted into the queue).
T get();
Returns and removes the first item in the queue (the item least recently inserted into the queue).
bool isEmpty() const;
Returns true if there are no items in the queue, otherwise false.
void insert(T a);
Inserts the item a at the end of the queue.
T last() const;
Returns, but does not remove, the last item in the queue (the item most recently inserted into the queue).
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.