C++ Stack empty() functionC++ Stack empty() function is used for testing whether the container is empty or not. In many cases, before extracting the actual elements from the stack, programmers give preference to check whether the stack does have some elements or not. Doing so is advantageous regarding memory and cost. SyntaxParametersThere are no parameters. Since the function is used only for testing purpose, so it is directly applied to the stack. Hence no arguments are passed. Return valueIf the container under reference is empty, then the method returns 'true' else returns 'false'. The method is used only for the purpose of testing so based on the test results values are returned. Example 1//The program given below is used for the detection of emptiness of a container. Output: Result is: 55 Example 2//The program given below is used for the detection of emptiness of a container. Output: Elements are present in the stack ComplexityThe function is used only for the detection of emptiness of the container, hence accepts no parameters and has constant complexity. Data racesOnly the container is accessed. The stack is accessed to check for the presence of elements. Not all the elements are accessed by this function but a glance is made to check if the container is totally empty or has some presence. Exception SafetyGuarantee as equivalent to the operations that are performed on the underlying container object is provided. Next TopicC++ Stack |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India