c++ stl stack_C ++ STL中的stack :: empty()函数

骑猪看日落 2023-03-05 12:50 120阅读 0赞

c++ stl stack

Prototype:

原型:

  1. stack<T> st; //declaration
  2. st.empty();

Parameter:

参数:

  1. No parameter passed

Return type: Bool (True or False)

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

  • True: Stack is empty

    正确:堆栈为空

  • False: Stack is not empty

    False:堆栈不为空

Header file to be included:

包含的头文件:

  1. #include <iostream>
  2. #include <stack>
  3. OR
  4. #include <bits/stdc++.h>

Usage:

用法:

The function checks whether a stack is empty or not.

该函数检查堆栈是否为空。

Time complexity: O(1)

时间复杂度:O(1)

Example:

例:

  1. For a stack of integer,
  2. stack<int> st;
  3. st.push(4);
  4. st.push(5);
  5. stack content:
  6. 5
  7. C++ implementation:
  8. Output
  9. ...use of empty function...
  10. stack elements are:
  11. top element is:6
  12. top element is:5
  13. top element is:4
  14. stack empty
  15. 3 pop operation performed total to make stack empty
  16. TOP Interview Coding Problems/Challenges Run-length encoding (find/print frequency of letters in a string) Sort an array of 0's, 1's and 2's in linear time complexity Checking Anagrams (check whether two string is anagrams or not) Relative sorting algorithm Finding subarray with given sum Find the level in a binary tree with given sum K Check whether a Binary Tree is BST (Binary Search Tree) or not 1[0]1 Pattern Count Capitalize first and last letter of each word in a line Print vertical sum of a binary tree Print Boundary Sum of a Binary Tree Reverse a single linked list Greedy Strategy to solve major algorithm problems Job sequencing problem Root to leaf Path Sum Exit Point in a Matrix Find length of loop in a linked list Toppers of Class Print All Nodes that don't have Sibling Transform to Sum Tree Shortest Source to Destination Path Comments and Discussions Ad: Are you a blogger? Join our Blogging forum. Please enable JavaScript to view the comments powered by Disqus.

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

c++ stl stack

发表评论

表情:
评论列表 (有 0 条评论,120人围观)

还没有评论,来说两句吧...

相关阅读

    相关 C++ stack(STL stack)

    容器适配器是一个封装了序列容器的类模板,它在一般序列容器的基础上提供了一些不同的功能。之所以称作适配器类,是因为它可以通过适配容器现有的接口来提供不同的功能。 sta

    相关 STL_stack/STL_queue

    1、stack stack 模板类的定义在<stack>头文件中。 stack 模板类需要两个模板参数,一个是元素类型,一个容器类型,但只有元素类型是必要 的,在不