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

淡淡的烟草味﹌ 2023-03-05 12:43 50阅读 0赞

c++ stl stack

Prototype:

原型:

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

Parameter:

参数:

  1. No parameter passed

Return type: int

返回类型: int

Header file to be included:

包含的头文件:

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

Usage:

用法:

The function returns the current size of the stack.

该函数返回堆栈的当前大小。

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 size function...
  10. stack size is: 3
  11. stack elements are:
  12. top element is:6
  13. top element is:5
  14. top element is:4
  15. stack empty
  16. stack size is: 0
  17. 3 pop operation performed total to make stack empty
  18. TOP Interview Coding Problems/Challenges
  19. Run-length encoding (find/print frequency of letters in a string)
  20. Sort an array of 0's, 1's and 2's in linear time complexity
  21. Checking Anagrams (check whether two string is anagrams or not)
  22. Relative sorting algorithm
  23. Finding subarray with given sum
  24. Find the level in a binary tree with given sum K
  25. Check whether a Binary Tree is BST (Binary Search Tree) or not
  26. 1[0]1 Pattern Count
  27. Capitalize first and last letter of each word in a line
  28. Print vertical sum of a binary tree
  29. Print Boundary Sum of a Binary Tree
  30. Reverse a single linked list
  31. Greedy Strategy to solve major algorithm problems
  32. Job sequencing problem
  33. Root to leaf Path Sum
  34. Exit Point in a Matrix
  35. Find length of loop in a linked list
  36. Toppers of Class
  37. Print All Nodes that don't have Sibling
  38. Transform to Sum Tree
  39. Shortest Source to Destination Path
  40. Comments and Discussions
  41. Ad:
  42. Are you a blogger? Join our Blogging forum.
  43. Please enable JavaScript to view the
  44. comments powered by Disqus.

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

c++ stl stack

发表评论

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

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

相关阅读

    相关 C++ stack(STL stack)

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

    相关 STL_stack/STL_queue

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