Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

File name 'Empty' added in set code snippet #711

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions snippets/set/empty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Author : Chirag Chandel
Date : 15/06/2023
Time : 10:00
Description : This method returns true if their is no any element present in the set else returns false.
*/

#include<iostream>
#include<set>

int main() {
// Create a set object holding integers
std::set<int> s1{ 14, 12, 15, 11, 10 };
std::set<int> s2{};

std::bool check1 = s1.empty();
std::bool check2 = s2.empty();

// print message if set is not empty
if (check1) {
std::cout << "Set is Empty" << std::endl;
}
else {
std::cout << "Set is Not Empty" << std::endl;
}

//print message if set is empty
if (check2) {
std::cout << "Set is Empty" << std::endl;
}
else {
std::cout << "Set is Not Empty" << std::endl;
}

return 0;
}