栈
Wade_Gao
这个作者很懒,什么都没留下…
展开
-
LeetCode-224: 基本计算器
一、题目描述 二、解题思路 将中缀表达式转换为后缀表达式。 三、解题代码 class Solution { private: static unordered_map<char, int> icp, isp; stack<char> stk; string src; string sln; void Back(); int calc(int tmp1, char oper, int tmp2); public: int ca原创 2020-07-07 19:30:16 · 147 阅读 · 0 评论 -
浙大版《数据结构(第2版)》题目集习题3.11 表达式转换 (25分)
一、题目描述 算术表达式有前缀表示法、中缀表示法和后缀表示法等形式。日常使用的算术表达式是采用中缀表示法,即二元运算符位于两个运算数中间。请设计程序将中缀表达式转换为后缀表达式。 输入格式: 输入在一行中给出不含空格的中缀表达式,可包含+、-、*、\以及左右括号(),表达式不超过20个字符。 输出格式: 在一行中输出转换后的后缀表达式,要求不同对象(运算数、运算符号)之间以空格分隔,但结尾不得有多余空格。 输入样例: 2+3*(7-4)+8/4 输出样例: 2 3 7 4 - * + 8 4 / + 二、解原创 2020-07-06 22:22:39 · 1400 阅读 · 0 评论 -
LeetCode面试题 03.01: 三合一
First. Problem’s Description Second. Problem’s Solution I don’t think there is any point that’s difficult to solve. Three. Code For Solution class TripleInOne { private: int *Data; int sSize = -1; unsigned int s_begin[3]; unsigned int s_cu原创 2020-05-12 21:36:21 · 212 阅读 · 0 评论 -
PTA数据结构与算法题目集(中文)-6-7: 在一个数组中实现两个堆栈
一、题目描述 本题要求在一个数组中实现两个堆栈。 函数接口定义: Stack CreateStack( int MaxSize ); bool Push( Stack S, ElementType X, int Tag ); ElementType Pop( Stack S, int Tag ); 其中Tag是堆栈编号,取1或2;MaxSize堆栈数组的规模;Stack结构定义如下: typedef int Position; struct SNode { ElementType *Data;原创 2020-05-11 01:11:12 · 314 阅读 · 0 评论 -
LeetCode-面试题 03.04:化栈为队
class MyQueue { private: stack<int> s1, s2; public: /** Initialize your data structure here. */ MyQueue() { } /** Push element x to the back of queue. */ void push(i...原创 2020-04-29 22:02:29 · 162 阅读 · 0 评论 -
Huawei:反转句子单词
一、问题描述 二、解题思路 很明显,用到栈来保存单词,用双指针解决。 首先去掉字符串的前导空格 从头到尾扫描字符串,以空格来区分不同的单词 每次找到一个单词后,将一个空格压入栈内 扫描得到一个单词后,将快指针作为新的起点,令慢指针指向和快指针相等的位置,即令慢指针作为新的起点,重复操作上述过程,直到结束 三、解题代码 #include <iostream> #include <...原创 2020-04-05 22:22:02 · 149 阅读 · 0 评论