TheDeveloperBlog.com

Home | Contact Us

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

C++ Queue pop() Function

C++ Queue pop() 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 pop() Function

C++ Queue pop() function is used for removing the topmost element of the queue. The function is implied only for deletion of elements.

Syntax

void pop()

Parameters

The function only performs the deletion operation and does not accept any parameters.

Return value

There is no return value for this function; it is only implied for deletion of elements.

Example 1

#include <iostream>
#include <queue>
int main()
{

		std::queue<int> newqueue;
		int qint;
		std::cout << "Enter some valid integer values(press 0 to end)";
		do
		{
			std::cin>> qint;
			newqueue.push(qint);
		}	while (qint);
	
		std::cout << "newqueue contains: ";
		while(!newqueue.empty())
		{
			std::cout <<" " <<newqueue.front();
			newqueue.pop();
		}
		return 0;
}

Output:

Enter some valid integer values(press 0 to end)
1 
3
4
5
6
7
0
newqueue contains: 1 3 4 5 6 7 0

Example 2

#include <iostream>
#include <queue>
using namespace std;
int main()
{
	{
		int a=0;
		queue<int> newqueue;
		newqueue.push(4);
		newqueue.push(8);
		newqueue.push(12);
		newqueue.push(16);
		while(!newqueue.empty())
		{
			newqueue.pop();
			a++;
		}
		cout<<a;
	}
}

Output:

4

Complexity

The complexity of the function is constant.

Data races

This function modifies the container and all of its elements. After the deletion of an element from the queue, respective positions of all the other elements are also modified.

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