English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++The queue function returns the last element of the queue. Here, the last element is the most recent element. That is, it returns the last added element.
value_type& back(); const value_type& back() const;
This function does not take any parameters. It is used only to return the value of the last element.
This function returns the last element of the queue.
#include <iostream> #include <queue> int main() { std::queue<int> newqueue; newqueue.push(24); newqueue.push(80); newqueue.back () += newqueue.front(); std::cout << "newqueue.back() modified to" << newqueue.back(); return 0; }
Output:
Modify newqueue.back() to 104
The complexity of the function is constant.
This function accesses the container. To return the last element, it accesses the entire queue container and then provides the value of the latest element.
It provides guarantees equivalent to operations performed on underlying container objects.