A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_stack_operator_greater_than_or_equal_to.htm below:

C++ Stack::operator>= Function

C++ Stack::operator>= Function

The C++ function std::stack::operator>= function is used to check compare the two stacks. It checks whether the elements in one stack is greaterthan or equal to the another stack. This function may return undefine result, if th sizes of the stacks are different. It return true if the elements of the first stack is greaterthan or equal to the corresponding elements of the second stack, otherwise it returns false.

Syntax

Following is the Syntax for std::stack::operator>= function −

bool operator>=(const stack <Type, Container>& left, const stack <Type, Container>& right);
Parameters Return value

Returns true if first stack is greater than or equal to second otherwise false.

Example 1

Let's look at the following where we are going to compare the sizes of two stacks x and y.

#include <iostream>
#include <stack>

int main() {
   std::stack<int> x, y;
   x.push(11);
   x.push(22);
   x.push(33);
   y.push(44);
   y.push(55);
   if (x.size() >= y.size()) {
      std::cout << "True";
   } else {
      std::cout << "False";
   }

   return 0;
}
Output

Let us compile and run the above program, this will produce the following result −

True
Example 2

Considering the following example, where we are going to check if the stack size is greaterthan or equal to specified value.

#include <iostream>
#include <stack>

int main(){
   std::stack<int> x;
   x.push(11);
   x.push(22);
   int value = 4;
   if (x.size() >= value) {
      std::cout << "True, Stack size is greaterthan or equal to" <<value<<".";
   } else {
      std::cout << "False, Stack size is Not greaterthan or equal to " <<value<<".";
   }
   return 0;
}
Output

If we run the above code it will generate the following output −

False, Stack size is Not greaterthan or equal to 4.
Example 3

In the following example, we are going to observe the usage of std::stack::operator>= function.

#include <iostream>
#include <stack>
using namespace std;

int main(void){
   stack<int> s1;
   stack<int> s2;
   for (int i = 0; i < 5; ++i) {
      s1.push(i + 1);
      s2.push(i + 1);
   }
   s1.push(6);
   if (s1 >= s2)
      cout << "Stack s1 is greater than or equal to s2." << endl;
   s2.push(7);
   if (!(s1 >= s2))
      cout << "Stack s1 is not greater than or equal to s2." << endl;
   return 0;
}
Output

Let us compile and run the above program, this will produce the following result−

Stack s1 is greater than or equal to s2.
Stack s1 is not greater than or equal to s2.

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4