TheDeveloperBlog.com

Home | Contact Us

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

C++ Queue size() Function

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

C++ Queue size() function returns the number of queue elements. The number of elements in the queue is an actual representation of the size, and the size value is given by this function.

Syntax

size_type size() const;

Parameters

The function does not take any parameter, and it just returns the queue size.

Return value

The number of elements in the queue is returned. In other words, the size of the queue is given.

Example 1

#include <iostream>
#include <queue>
int main()
{
	std::queue<int> newqueue;
	std::cout<< "0. size: "<< newqueue.size();
	for(int j=0; j<5; j++)
	newqueue.push(j);
	std::cout<<"\n";
	std::cout << "1. size: " << newqueue.size();
	newqueue.pop();
	std::cout<<"\n";
	std::cout << "2. size: "<< newqueue.size();
	return 0;
}

Output:

0.size: 0
1.size: 5
2.size: 4

Example 2

#include <iostream>
#include <queue>
using namespace std;
int main()
{
	int result = 0;
	queue<int> newqueue;
	newqueue.push(12);
	newqueue.push(24);
	newqueue.push(36);
	newqueue.push(48);
	cout<<"Size of the queue is ";
	cout<<newqueue.size();
	return 0;
}

Output:

Size of queue is 4

Complexity

The complexity is constant.

Data races

The function accesses the container. By accessing the container the size of the queue is evaluates.

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