empty(): It returns true if the vector is empty , otherwise returns false.
If vector is empty then, begin() == end().
Parameters: Their is no parameter for this function.
Syntax:
vecName.empty()
For Example:
vec = {1,2,3,4}
vec.empty() => It returns false.
vec = {}
vec.empty() = > It returns true
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){vector<int> vec = {1, 2, 3, 4};if (vec.empty())cout << "Vector is empty\n";elsecout << "Vector is not empty\n";return 0;}
No comments:
Post a Comment