Cracking The Coding Interview 3.5
//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的更多相关文章
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- 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 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- 《Cracking the Coding Interview》——第13章:C和C++——题目6
2014-04-25 20:07 题目:为什么基类的析构函数必须声明为虚函数? 解法:不是必须,而是应该,这是种规范.对于基类中执行的一些动态资源分配,如果基类的析构函数不是虚函数,那么 派生类的析构 ...
- 《Cracking the Coding Interview》——第5章:位操作——题目7
2014-03-19 06:27 题目:有一个数组里包含了0~n中除了某个整数m之外的所有整数,你要设法找出这个m.限制条件为每次你只能用O(1)的时间访问第i个元素的第j位二进制位. 解法:0~n的 ...
- 二刷Cracking the Coding Interview(CC150第五版)
第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...
- 《Cracking the Coding Interview 》之 二叉树的创建 与 遍历(非递归+递归version)
#include <iostream> #include <cstdio> #include <vector> #include <stack> #de ...
随机推荐
- stm32cube使用
1.使用stm32cube生成CAN代码注意事项: a.需要手动配置CAN过滤器 { CAN_FilterConfTypeDef sFilterConfig; uint32_t filterID = ...
- centos 安装 FLEXPART
师哥做了个课题,用FLEXPART分析大气伴飞轨迹,提前先安装这个软件吧.我使用的环境是centos7,看官慢慢看,结尾有彩蛋~ 准备工作,flexpart是用Fortran语言写的,以.90结尾的文 ...
- English Voice of <<Bye Bye Bye>>
Bye Bye Bye - Lovestoned When i see you, looking back at me 当我看到你回首看我时 Watching this eye still 彼此凝视 ...
- C# 测试代码段性能耗时
一: DateTime BeginTime = System.DateTime.Now; //代码 DateTime EndTi ...
- LeetCode--342--4的幂
问题描述: 给定一个整数 (32 位有符号整数),请编写一个函数来判断它是否是 4 的幂次方. 示例 1: 输入: 16 输出: true 示例 2: 输入: 5 输出: false 进阶:你能不使用 ...
- genymotio安装apk包提示 ...abi ...cpu
下载 Genymotion-ARM-Translation_v1.1 (1).zip 地址:http://qc1.androidfilehost.com/dl/Q-YDDKt4QaFNvKh62ppO ...
- Integer to English words leetcode java
问题描述: Convert a non-negative integer to its english words representation. Given input is guaranteed ...
- 第一阶段——站立会议总结DAY04
1.昨天做了什么:未取得一点进步. 2.今天准备做什么:准备在网上搜索一下微信个人中心的相关信息,代码资料. 3.遇到的困难:界面简陋,还是对于深层次的,比如逻辑,还是不怎么会用.
- PAT 1035 Password
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- 基本数据类型int,bool,str
.基本数据类型(int,bool,str) 基本数据数据类型: int 整数 str 字符串. 一般不存放大量的数据 bool 布尔值. 用来判断. True, False list 列表.用来存放大 ...