C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ Queue back() FunctionC++ Queue function returns the value of the last element of the queue. Here last element is the one that is newest. The element which was most recently added is returned. Syntaxvalue_type& back(); const value_type& back() const; ParametersThe function does not take any parameters. It is only used to return the value of the last element. Return valueThe function returns the last element of the queue. Example#include <iostream> #include <queue> int main() { std::queue<int> newqueue; newqueue.push(24); newqueue.push(80); newqueue.back () += newqueue.front(); std::cout <<"newqueue.back() is modified to" << newqueue.back (); return 0; } Output: newqueue.back() is modified to 104 ComplexityThe complexity of the function is constant. Data racesThe function accesses the container. For returning the last element the whole queue container is accessed and then the value of the newest element is given. Exception SafetyGuarantee as equivalent to the operations that are performed on the underlying container object is provided.
Next TopicC++ Queue
|