首页 > 编程语言 >C++——stack和queue

C++——stack和queue

时间:2024-10-10 21:18:10浏览次数:3  
标签:力扣 优先级 运算符 C++ st queue push LeetCode stack

1.简介

栈和队列的定义和之前的容器有所差别

2.简单地使用

void test_stack1()
{
	stack<int> st;
	st.push(1);
	st.push(2);
	st.push(3);
	st.push(4);

	while (!st.empty())
	{
		cout << st.top() << " ";
		st.pop();
	}
	cout << endl;

}

void test_queue1()
{
	queue<int> q;
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);

	while (!q.empty())
	{
		cout << q.front() << " ";
		q.pop();
	}
	cout << endl;
}

3.练习题

1.232. 用栈实现队列 - 力扣(LeetCode)

2.155. 最小栈 - 力扣(LeetCode)

3.栈的压入、弹出序列_牛客题霸_牛客网 (nowcoder.com)

4.102. 二叉树的层序遍历 - 力扣(LeetCode)

5.150. 逆波兰表达式求值 - 力扣(LeetCode)

运算符的优先级顺序是由相邻两个运算符的优先级决定的

后缀表达式没有括号,括号是加强优先级的

标签:力扣,优先级,运算符,C++,st,queue,push,LeetCode,stack
From: https://blog.csdn.net/2301_80342122/article/details/142726076

相关文章

  • Boost C++ 库 | 智能指针(共享指针、共享数组、弱指针、介入式指针、指针容器)入门
    点击上方"蓝字"关注我们01、共享指针>>>这是使用率最高的智能指针,但是C++标准的第一版中缺少这种指针。它已经作为技术报告1(TR1)的一部分被添加到标准里了。如果开发环境支持的话,可以使用 memory 中定义的 std::shared_ptr。在BoostC++库里,这个智能指针命名为......
  • 实验1 现代C++基础编程
    任务1:源代码task1.cpp1#include<iostream>2#include<string>3#include<vector>4#include<algorithm>56usingnamespacestd;78template<typenameT>9voidoutput(constT&c);1011voidtest1();12void......
  • 实验1 现代c++编程初体验
    任务1:task1.cpp1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参67#include<iostream>8#include<string>......
  • 实验1 C++
    #include<iostream>#include<string>#include<vector>#include<algorithm>usingnamespacestd;template<typenameT>voidoutput(constT&c);voidtest1();voidtest2();voidtest3();intmain(){cout<<&q......
  • 实验一 现代C++编程初体验
    实验结论:任务一:task1.cpp1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参67#include<iostream>8#include<......
  • C++常用设计模式详解
    前言:本文详细解释几种常用的C++设计模式,都是平时项目中用的比较多的。本文针对每种设计模式都给出了示例,让你跟着代码彻底搞懂设计模式。Tips:如果是准备面试,不需要知道所有的设计模式,要深入理解下面几种常用即可,因为面试官会先问你了解哪些设计模式,然后从你了解的里面挑一......
  • c++(自创游戏6)
    1.自创游戏6作者在家里看见了一本书,书名叫:小学生趣味编程,大人也可以看,作者在上面找到了,if,下面是作者自己创作的小游戏,想玩的复制一下就行了,上代码。#include<bits/stdc++.h>#include<windows.h>usingnamespacestd;intmain(){inta;cout<<"请开始游玩if游戏"......
  • 实验1 现代C++编程初体验
    任务1://现代C++标准库、算法库体验//本例用到以下内容://1.字符串string,动态数组容器类vector、迭代器//2.算法库:反转元素次序、旋转元素//3.函数模板、const引用作为形参#include<iostream>#include<string>#include<vector>#include<algorithm>usin......
  • c++初始化列表构造
      #include<iostream>#include<string>usingnamespacestd;classCar{public: stringbrand; intyear; stringtype; //无参构造函数 Car(){ cout<<"无参构造函数"<<endl; } //带一个参数的构造函数 Car(stringb) { cout<<&qu......
  • 《C++代码热更新:为高效开发注入新活力》
    一、引言在软件开发的过程中,我们常常面临着这样的挑战:当程序已经部署到生产环境后,发现了一些需要紧急修复的bug或者需要添加新的功能。传统的方法是停止程序运行,进行代码修改,然后重新编译、部署,这个过程不仅耗时,还可能会影响到用户的使用体验。而代码热更新技术的出现,为......