TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C++ Queue front() Function

C++ Queue front() Function with Examples on tutorial for beginners and professionals, constructor, emplace(), empty(), pop(), push(), back(), size(), top(), object and class, exception, static, structs, inheritance, aggregation etc.

<< Back to CPP

C++ queue front() Function

C++ Queue front() function returns the value of the front element of the queue. The first element is the oldest element or the element which was initially added to the queue. The function is used to return that element.

Syntax

value_type& front();
const value_type& front() const;

Parameters

The function does not take any parameter, it is only used to return the value of the oldest element or the element at the front end of the queue.

Return value

The function returns the front element of the queue.

Example 1

#include <iostream>
#include <queue>
int main()
{
	std::queue<int> newqueue;
	newqueue.push(24);
	newqueue.push(80);
	newqueue.front () +=20;
	std::cout <<"newqueue.front() is modified to " << newqueue.front();
	return 0;
}

Output:

newqueue.front() is modified to 44

Example 2

#include <iostream>
#include <queue>
using namespace std;
int main()
{
	queue<int> newqueue;
	newqueue.push(11);
	newqueue.push(22);
	newqueue.push(33);
	cout << newqueue.front();
	return 0;
}

Output:

11

Complexity

The complexity of the function is constant.

Data races

The function accesses the container. The queue container as a whole is accessed, and then the element which is the oldest is returned.

Exception Safety

Guarantee as equivalent to the operations that are performed on the underlying container object is provided.

Next TopicC++ Queue




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf