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

c++ stl stack

Prototype:

原型:

    stackst; //declaration
st.push(T item);

Parameter:

参数:

    T item; //T is the data type

Return type: void

返回类型: void

Header file to be included:

包含的头文件:

    #include <iostream>
#include <stack>
OR
#include <bits/stdc++.h>

Usage:

用法:

The function pushes elements to the stack.

该函数将元素压入堆栈。

Time complexity: O(1)

时间复杂度:O(1)

Example:

例:

    For a stack of integer,
stack<int> st;
st.push(4);
st.push(5);
stack content:
5 

C++ implementation:

Output

...use of push function...
stack elements are:
5
4


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.


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

c++ stl stack

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/546163.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

if快还是switch快?解密switch背后的秘密

这是我的第 57 篇原创文章条件判断语句是程序的重要组成部分&#xff0c;也是系统业务逻辑的控制手段。重要程度和使用频率更是首屈一指&#xff0c;那我们要如何选择 if 还是 switch 呢&#xff1f;他们的性能差别有多大&#xff1f;switch 性能背后的秘密是什么&#xff1f;接…

MySQL replace into (insert into 的增强版)

在使用SQL语句进行数据表插入insert操作时&#xff0c;如果表中定义了主键&#xff0c;插入具有相同主键的记录会报错&#xff1a; Error Code: 1062. Duplicate entry XXXXX for key PRIMARY(主键冲突) 这样我们只好检查主键是不是存在&#xff0c;若存在则更新&#xff0c;若…

最大连续子序列和问题

问题描述&#xff1a;给定一个序列a[1],a[2]...a[n]&#xff0c;求解其连续子序列中元素和的最大值 例如&#xff1a; 6 -1 5 4 -7 这个序列最大连续子序列和为14 具体问题见&#xff1a; [urlhttp://acm.hdu.edu.cn/showproblem.php?pid1003]HDOJ 1003[/url] [urlhttp://acm.…

js 数组添加n次相同元素_数组中两次出现相同元素之间的最大距离

js 数组添加n次相同元素Prerequisite: Hashing data structure 先决条件&#xff1a; 哈希数据结构 Problem statement: 问题陈述&#xff1a; Find maximum distance between two occurrences of same element in the array. 查找两次出现的相同元素在数组中的最大距离。 E…

一道题决定去留:为什么synchronized无法禁止指令重排,却能保证有序性?

前几天有一位读者找我问一个问题&#xff0c;说是这道题可能影响了他接下来3年的技术成长。据说这位读者前面的很多问题会的都还可以&#xff0c;属于那种可过可不过的类型的&#xff0c;面试官出了最后一道题&#xff0c;就是回答的满意就可以给Offer&#xff0c;回答的不好就…

haskell程序设计语言

根据[urlhttp://www.haskell.org/haskellwiki/Haskell]haskell[/url]的[urlhttp://www.haskell.org/haskellwiki/Introduction]官方定义[/url]&#xff0c;haskell是polymorphically(多态&#xff09; statically typed静态类型&#xff09;, lazy&#xff08;懒计算&#xff0…

【Android开发】之Fragment与Acitvity通信

上一篇我们讲到与Fragment有关的常用函数&#xff0c;既然Fragment被称为是“小Activity”&#xff0c;现在我们来讲一下Fragment如何与Acitivity通信。如果上一篇还有不懂得&#xff0c;可以再看一下。传送门。 Fragment与Activity通信的方式如下&#xff1a; 一、通过初始化函…

next和hasnext_使用Java中的next()和hasNext()方法遍历List元素

next和hasnextGiven a List of integers and we have to traverse, print all its element using next() and hasNext() methods. 给定一个整数列表&#xff0c;我们必须遍历&#xff0c;使用next()和hasNext()方法打印其所有元素。 什么是hasNex()和next()方法&#xff1f; (…

「递归」的正确打开方式,看不懂你打我~

这是磊哥的第 189 期分享作者 | 田小齐来源 | 码农田小齐&#xff08;ID&#xff1a;NYCSDE&#xff09; 分享 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;前言 递归&#xff0c;是一个非常重要的概念&#xff0c;也是面试中非常喜欢考的。因为它不但能考察…

Log4cpp 使用手册

参考资料&#xff1a; log4cpp 配置 与 使用http://www.cnblogs.com/welkinwalker/archive/2011/06/23/2088197.html 便利的开发工具-log4cpp快速使用指南 http://www.ibm.com/developerworks/cn/linux/l-log4cpp/ Log4cpp配置文件格式说明 http://sogo6.iteye.com/blog/115431…

适合初学编程的一些项目

学习了一门语言以及数据结构之后&#xff0c;通常需要做一些项目来巩固所学的知识&#xff0c;我感觉最好是用写一些简单的小工具或者小游戏&#xff0c;能够提高自己的编程能力&#xff0c;也能进一步提高自己学习的兴趣。最好的是将自己想做的事情用程序的实现&#xff0c;比…

python 5的倍数_查找所有低于1000的数字的和,这是Python中3或5的倍数

python 5的倍数Sometimes, we need to find the sum of all integers or numbers that are completely divisible by 3 and 5 up to thousands, since thousands are a too large number that’s why it becomes difficult for us. So, here we will do it in Python programmi…

switch 的性能提升了 3 倍,我只用了这一招!

这是我的第 190 期分享作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09; 分享 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;上一篇《if快还是switch快&#xff1f;解密switch背后的秘密》我们测试了 if 和 switch 的性能&am…

HashMap get不出对象时出错 解决

为什么80%的码农都做不了架构师&#xff1f;>>> 如题&#xff1a; Map map new HashMap(); map.put("1", "A"); map.put("2", "A"); map.put("3", "A"); map.put("4", "A")…

安装codeblocks和wxwidgets及opencv

codeblocks 是一款开放源代码的跨平台的c/c++集成开发环境,它是用wxwidgets 开发的,并且支持插件,功能很强大。可以用来在windows开发各种程序。下面记录一下我安装该软件的过程: 首先到http://www.codeblocks.org/downloads 下载该软件,选择含mingw的文件(codeblocks-10…

Java LinkedList boolean addAll(int index,Collection c)方法,带有示例

LinkedList boolean addAll(int index&#xff0c;Collection c)方法 (LinkedList boolean addAll(int index, Collection c) method) This method is available in package java.util.Collection and here, Collection is an interface. 该方法在java.util.Collection包中可用…

高质量SQL的30条建议!(后端必备)

这是我的第 191 期分享作者 | 捡田螺的小男孩来源 | 捡田螺的小男孩&#xff08;ID&#xff1a;gh_873ad5979a0b&#xff09; 分享 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;本文将结合实例demo&#xff0c;阐述30条有关于优化SQL的建议&#xff0c;多数…

滤波电容的选择(调试中)

整个系统高电平时12V&#xff0c;信号是ms级的负脉冲&#xff0c;脉冲的下降沿很陡&#xff0c;当用示波器展开看的时候&#xff0c;发现了低于0V的过冲&#xff0c;能低到-6V&#xff08;相当严重&#xff09;&#xff0c;这是在整个箱子的出口处测量到的。在主控板&#xff0…

sicp

sicp (structure and interpretion of computer programs &#xff0c;编号为6.001 )是麻省理工学院的一门经典计算机入门课程&#xff0c;虽然近年被另外一门课程所取代&#xff08;6.00 或6.01 &#xff09;&#xff0c;但最近好像有复活 的迹象。Perter Norvig 写了关于sicp…

Redis的自白:我为什么在单线程的这条路上越走越远?

这是我的第 192 期分享作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;我是 Redis&#xff0c;今年 11 岁了~曾几何时我是辣么的单纯&#xff0c;辣么的可爱&#xff0c;而如…