stl中empty_C ++ STL中的set :: empty()函数

news/2024/7/19 16:29:37 标签: python, java, mysql, sql, js

stl中empty

C ++ STL set :: empty()函数 (C++ STL set::empty() function)

set::empty() function is a predefined function, it is used to check whether a set is empty or not. If set is empty it returns true (1), if set is not empty it returns false (0).

set :: empty()函数是预定义的函数,用于检查集合是否为空。 如果set为空,则返回true (1),如果set不为空,则返回false (0)。

Prototype:

原型:

    set<T> st; //declaration
    set<T>::iterator it; //iterator declaration
    st.empty( ); 

Parameter: Nothing to pass

参数:无通过

Return type: Bool (True or False)

返回类型:布尔型(True或False)

Usage: The function checks whether the set is empty or not.

用法:该函数检查集合是否为空。

Example:

例:

    For a set of integer,
    set<int> st;
    st.insert(4);
    st.insert(5);
    set content:
        4
        5

    Bool check=st.empty();  
    check =False

    St.erase(st.begin()); //erases 4
    St.erase(st.begin()); //erases 5
    Set content:
    Empty set 
    
    //now check again
    check=st.empty()
    check=TRUE

Header file to be included:

包含的头文件:

    #include <iostream>
    #include <set>
    OR
    #include <bits/stdc++.h>

C++ implementation:

C ++实现:

#include <bits/stdc++.h>
using namespace std;

void printSet(set<int> st){
	set<int>:: iterator it;
	cout<<"Set contents are:\n";
	for(it=st.begin();it!=st.end();it++)
		cout<<*it<<" ";
	cout<<endl;
}

int main(){
	cout<<"Example of empty function\n";
	set<int> st;
	set<int>:: iterator it;
	cout<<"inserting 4\n";
	st.insert(4);
	cout<<"inserting 6\n";
	st.insert(6);
	cout<<"inserting 10\n";
	st.insert(10);

	printSet(st); //printing current set

	if(st.empty())
	cout<<"It's empty\n";
	else
	cout<<"It's not empty\n";

	cout<<"erasing all elements\n";
	st.clear();
	
	if(st.empty())
		cout<<"It's empty\n";
	else
		cout<<"It's not empty\n";

	return 0;
}

Output

输出量

Example of empty function
inserting 4
inserting 6
inserting 10
Set contents are:
4 6 10
It's not empty
erasing all elements
It's empty


翻译自: https://www.includehelp.com/stl/set-empty-function-in-cpp-stl.aspx

stl中empty


http://www.niftyadmin.cn/n/1254086.html

相关文章

20181127-2 每周例行报告

此作业要求参见&#xff1a;[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2447] 一、本周PSP表格 总计&#xff1a;238min 二、本周进度表 三、代码累积折线图 四、博客字数累积图 五、本周PSP饼状图 六、PSP时间累积图 转载于:https://www.cnblogs.com/handsome-b…

ruby hash方法_Ruby中带有示例的Hash.eql?()方法

ruby hash方法Hash.eql&#xff1f;()方法 (Hash.eql?() Method) In this article, we will study about Hash.eql?() Method. The working of this method can be predicted with the help of its name but it is not as simple as it seems. Well, we will understand this…

Java Socket通信以及可能出现的问题解决

https://www.cnblogs.com/shakinghead/p/7647761.html 待总结转载于:https://www.cnblogs.com/genggeng/p/10066225.html

codd's是什么_EF-Codd的12条黄金法则| 数据库管理系统

codds是什么In 1970’s DR. EF-Codd published a paper, titled a Relational Model of Data for large shared databases. This paper becomes the all development RDBMS. In support of their relational model, Dr. EF-Codd also proposed 12 rules which are known as 12 …

线性代数中两个向量相乘_加两个向量| Python的线性代数

线性代数中两个向量相乘Prerequisite: Linear Algebra | Defining a Vector 先决条件&#xff1a; 线性代数| 定义向量 In the python code, we will add two vectors. We can add two vectors only and only if the both the vectors are in the same dimensional space. For…

【Cocos Creator实战教程(10)】——UI组件(4)Slider 组件

1. 相关知识点 Slider是一个滑动器组件 1.1 Slider组件 点击 属性检查器下面的添加组件按钮&#xff0c;然后从添加UI组件中选择Slider&#xff0c;即可添加Slider组件到节点上。 1.2 Slider属性 属性功能说明Handle滑动按钮部件&#xff0c;可以通过该按钮进行滑动调节Slider数…

linux tcp服务器软件,linux下tcp服务器源码示例

#include #include #include #include #include #include #include #include #include #include #include struct _NSS_HEADER{unsigned short ProtocolVersion; /* 协议版本信息 */unsigned short MsgType; /* 消息类型 */unsigned short TransactionNo; /* 传输编号 */unsign…

展位招募_展位算法 计算机科学组织

展位招募展位算法 (Booths algorithm) This is a kind of algorithm which uses a more straightforward approach. This algorithm also has the benefit of the speeding up the multiplication process and it is very efficient too. Binary multiplication which has sign…