栈和队列
zhaohoutao
这个作者很懒,什么都没留下…
展开
-
LeetCode-225 用队列实现栈
用队列实现栈class MyStack {public: /** Initialize your data structure here. */ MyStack() { } /** Push element x onto stack. */ void push(int x) { //主要实现的是:将一个队列的元素添加到...原创 2019-06-29 17:34:09 · 106 阅读 · 0 评论 -
LeetCode-232 用栈实现队列
用栈实现队列class MyQueue {public: /** Initialize your data structure here. */ MyQueue() { } /** Push element x to the back of queue. */ void push(int x) { //临时变量的stack stack<int> temp; ...原创 2019-06-29 18:29:41 · 148 阅读 · 0 评论 -
栈的压入和弹出
栈的压入和弹出自己的想法:class Solution {public: bool IsPopOrder(vector<int> pushV, vector<int> popV){ stack<int> temp; temp.push(pushV[0]); int len = pushV.size(); int biaozhi = 0; ...原创 2019-06-29 20:41:53 · 333 阅读 · 0 评论 -
LeetCode-224 基本计算器
基本计算器class Solution {public: int calculate(string s) { //使用方法是栈的使用 stack<int> nums; stack<char> signs; int flag = 0; long num = 0; int len = s.size(); for (int ii = 0; ii<l...原创 2019-06-29 23:45:34 · 737 阅读 · 0 评论 -
LeetCode-215 数组中的第k个最大元素
数组中的第k个最大元素class Solution {public: int findKthLargest(vector<int>& nums, int k) { //经典的考题 //使用最小堆的算法 int len=nums.size(); priority_queue<int,vector&...原创 2019-06-30 00:19:34 · 91 阅读 · 0 评论 -
LeetCode-295 数据流的中位数
数据流的中位数class MedianFinder {public: /** initialize your data structure here. */ MedianFinder() { } //使用最大堆和最小堆的辅助 void addNum(int num) { //保持中位数 if (zuixiaodui.empty() || zuixiaodui.top() &...原创 2019-06-30 13:16:41 · 116 阅读 · 0 评论 -
LeetCode-227 基本计算器2
基本计算器2class Solution {public: int calculate(string s) { stack<int> bolan; char sign = '+'; long num = 0; int len = s.size(); for (int i = 0; i<len; ++i) { char c = s[i]; if ...原创 2019-07-12 15:40:32 · 129 阅读 · 0 评论 -
求树的最大深度和最小深度的非递归实现
求树的最大深度和最小深度的非递归实现int long_depth(TreeNode* root){ //对于这种东西使用的是队列的方式 deque<TreeNode*> deque_tree; deque_tree.push_back(root); int depth = 0; int thislevel=1; int nextlevel=0; while (!deq...原创 2019-07-21 19:44:10 · 443 阅读 · 0 评论 -
使用栈排序
stack<int> zhan_paixu2(stack<int> s){ stack<int> r; while (!s.empty()) { int temp = s.top(); s.pop(); while (!r.empty() && r.top()>temp) { s.push(r.top());...原创 2019-08-19 23:17:53 · 153 阅读 · 0 评论