//Implement a MyQueue class which implements a queue using two stacks.
#include <iostream>
#include<stack>
using namespace std;
class MyQueue
{
public:
stack<int> data,buffer; MyQueue()
{
} void EnQueue(int e)
{
data.push(e);
} int DeQueue()
{
if (data.empty())
{
return -1;
} while(!data.empty())
{
buffer.push(data.top()) ;
data.pop(); }
int t = buffer.top();
buffer.pop(); while(!buffer.empty())
{
data.push(buffer.top());
buffer.pop();
}
return t;
} }; int main()
{
MyQueue s; for (int i =0; i<10; i++)
{
s.EnQueue(i);
}
cout<<endl; for (int i=0; i<10;i++)
{
cout<<s.DeQueue();
} return 0;
}

Cracking The Coding Interview 3.5的更多相关文章

  1. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  2. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  3. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  4. Cracking the Coding Interview(Stacks and Queues)

    Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...

  5. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  6. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  7. 《Cracking the Coding Interview》——第13章:C和C++——题目6

    2014-04-25 20:07 题目:为什么基类的析构函数必须声明为虚函数? 解法:不是必须,而是应该,这是种规范.对于基类中执行的一些动态资源分配,如果基类的析构函数不是虚函数,那么 派生类的析构 ...

  8. 《Cracking the Coding Interview》——第5章:位操作——题目7

    2014-03-19 06:27 题目:有一个数组里包含了0~n中除了某个整数m之外的所有整数,你要设法找出这个m.限制条件为每次你只能用O(1)的时间访问第i个元素的第j位二进制位. 解法:0~n的 ...

  9. 二刷Cracking the Coding Interview(CC150第五版)

    第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...

  10. 《Cracking the Coding Interview 》之 二叉树的创建 与 遍历(非递归+递归version)

    #include <iostream> #include <cstdio> #include <vector> #include <stack> #de ...

随机推荐

  1. python中集合及运算

    一.集合set()的特点: 集合的特点:有的可变,有的不可变:元素无次序,不可重复. 集合中的元素不能重复,可作为一种简单高效的元素去重方式. 集合没有索引,它的元素无次序,不是序列. 利用set() ...

  2. toad 快捷键大全

    现在在企业中,操作oracle数据库的客户端,除了PL/SQL外,使用的较多的就是TOAD了!toad记得F9执行全部sql和Ctrl + Enter执行选中sql就行了,有啥需要的再查吧.快捷设置在 ...

  3. eQTL | Expression quantitative trait loci | 数量性状位点 | 表达数量性状基因座

    一篇通俗的文章:eQTL Expression quantitative trait loci (eQTLs) are genomic loci that explain all or a fract ...

  4. Practical Node.js (2018版) 第4章: 模版引擎

    Template Engines: Pug and Handlebars 一个模版引擎是一个库或框架.它用一些rules/languages来解释data和渲染views. web app中,view ...

  5. hdu6331 Walking Plan

    题意: sol: 考虑floyed 直接暴力做的话复杂度是kn^3会炸. 考虑一个比较神仙的分块做法. 注意到我们是可以直接求单独某个k的矩阵,使用矩阵快速幂即可(取min的矩阵乘法). 单独求一次的 ...

  6. Linux中常用压缩打包工具

    Linux中常用压缩打包工具 压缩打包是常用的功能,在linux中目前常用的压缩工具有gzip,bzip2以及后起之秀xz.本文将介绍如下的工具常见压缩.解压缩工具以及打包工具tar. gzip2 直 ...

  7. 20165309 技能学习经验与C语言

    技能学习经验与C语言 技能学习经验 你有什么技能比大多人(超过90%以上)更好?针对这个技能的获取你有什么成功的经验?与老师博客中的学习经验有什么共通之处? 从小到大,或是出于兴趣.或是出于父母的要求 ...

  8. 区间逼近 牛客寒假1 小a的排列

    做法:模拟 萌区间也就是这个区间里的数是一段连续的数 做法的话是先找出题目x,y的位置,记为l,r,然后找出l,r内的最大最小值,又因为萌区间要求数是连续的,就从这段连续数最小的开始到最大的,确定缩放 ...

  9. java骰子求和算法

    //扔 n 个骰子,向上面的数字之和为 S.给定 Given n,请列出所有可能的 S 值及其相应的概率public class Solution { /** * @param n an intege ...

  10. SQL Server 创建触发器(trigger)

    update 触发器: if(OBJECT_ID('trigger_compost_up') is not null) drop trigger trigger_compost_up go creat ...