当前位置: 首页 > news >正文

廊坊做网站外包手机怎么创建网站

廊坊做网站外包,手机怎么创建网站,永州网站建设开发,网站多种语言是怎么做的目录 stack的定义 stack容器内元素的访问 stack常用函数实例解析 stack的常见用途 stack的定义 其定义的写法和其他STL容器相同&#xff0c;typename可以任意基本类型或容器&#xff1a; stack<typename> name; stack容器内元素的访问 由于栈本身就是一种后进先出…

目录

stack的定义

stack容器内元素的访问

stack常用函数实例解析

stack的常见用途

stack的定义

其定义的写法和其他STL容器相同,typename可以任意基本类型或容器:

stack<typename> name;

stack容器内元素的访问

由于栈本身就是一种后进先出的数据结构,在STL的stack中只能通过top()来访问栈顶元素。

#include<iostream>
#include<stack>
using namespace std;
int main(){stack<int> st;for(int i=1;i<=5;i++){st.push(i);}printf("%d\n",st.top());return 0;
}

stack常用函数实例解析

(1)push()

push(x)将x入栈,时间复杂度为O\left ( 1 \right )

(2)top()

top()获得栈顶元素,时间复杂度为O\left ( 1 \right )

(3)pop()

pop()用以弹出栈顶元素,时间复杂度为O\left ( 1 \right )

#include<stdio.h>
#include<stack>
using namespace std;
int main(){stack<int> st;for(int i=1;i<=5;i++){st.push(i);}for(int i=1;i<=3;i++){st.pop();}printf("%d\n",st.top());return 0;
}

(4)empty()

empty()可以检测stack内是否为空,返回true为空,返回false为非空,时间复杂度为O\left ( 1 \right )

#include<iostream>
#include<stack>
using namespace std;
int main(){stack<int> st;if(st.empty()==true){printf("Empty\n");}else{printf("Not Empty\n");}st.push(1);if(st.empty()==true){printf("Empty\n");}else{printf("Not Empty\n");}return 0;
}

(5)size()

size()返回stack内元素的个数,时间复杂度为O\left ( 1 \right )

#include<stdio.h>
#include<stack>
using namespace std;
int main(){stack<int> st;for(int i=1;i<=5;i++){st.push(i);}printf("%d\n",st.size());return 0;
}

stack的常见用途

stack用来模拟实现一些递归,防止程序对栈内存的限制而导致程序运行出错。

http://www.tj-hxxt.cn/news/68137.html

相关文章:

  • 做数学题网站济南网站制作公司
  • 做网站的是什么工作易搜搜索引擎
  • 做包装设计的网站有哪些北京seo服务商
  • 晋江做任务的网站seo外链平台热狗
  • 做网站伊犁哈萨克自治州网络互联网推广
  • 做三级分销网站设计windows优化大师提供的
  • 民制作网站价格朝阳区搜索优化seosem
  • 网站开发设株洲网站设计外包首选
  • .net网站内容管理系统网易最新消息新闻
  • 营销活动方案模板成都seo正规优化
  • 汉中市建设工程招投标信息网官网杭州seo网络推广
  • 代做网站修改维护纵横seo
  • 东莞小程序开发解决方案seo技巧是什么
  • wordpress台湾网店网站做优化一开始怎么做
  • 工商网站备案办法电工培训技术学校
  • 唐山正规做网站的公司网络营销策划方案ppt模板
  • 青岛做网站建设哪家好百度q3财报2022
  • 中山网站建设文化价位做网络推广工作怎么样
  • 网站建设文章官网怎么引流推广自己的产品
  • 橙子建站跳转微信网站推广优化的公司
  • 尚品中国网站小说引流推广
  • wordpress 修改入口文件qq群排名优化
  • 北京做网站哪家好页面关键词优化
  • 广元做网站的公司有效获客的六大渠道
  • win7局域网网站开发seo 优化一般包括哪些内容
  • wordpress配色字号在哪个文件seo服务包括哪些
  • 电子商务网站开发实训体会百度客服中心
  • 网站建设落地页引擎搜索优化
  • 轴承外贸网站怎么做律师推广网站排名
  • 西安网站建设seo实时热点新闻