zoukankan      html  css  js  c++  java
  • 面试金典--3.5

    http://www.cnblogs.com/wanghui9072229/archive/2011/11/22/2259391.html

    老题目了,4月份面腾讯实习的时候问了这道题,都不用写代码的。

     1 #include <iostream>
     2 #include <queue>
     3 #include <climits>
     4 #include <algorithm>
     5 #include <memory.h>
     6 #include <stdio.h>
     7 #include <ostream>
     8 #include <vector>
     9 #include <list>
    10 #include <cmath>
    11 #include <string>
    12 #include <stdexcept>
    13 #include <stack>
    14 using namespace std;
    15 
    16 class MyQueue
    17 {
    18     stack<int> stackpush;
    19     stack<int> stackpop;
    20 public:
    21     MyQueue()
    22     {
    23         
    24     }
    25     ~MyQueue()
    26     {
    27         
    28     }
    29     void enqueue(const int &elem)
    30     {
    31         stackpush(elem);
    32     }
    33     int dequeue()
    34     {
    35         if(stackpop.size() == 0)
    36         {
    37             if(stackpush.size() == 0)
    38                 throw std::out_of_range("queue is empty");
    39             else
    40             {
    41                 while(!stackpush.empty())
    42                 {
    43                     stackpop.push(stackpush.top());
    44                     stackpush.pop();                    
    45                 }
    46                 int val = stackpop.top();
    47                 stackpop.pop();
    48                 return val;
    49             }
    50         }
    51         else
    52         {
    53             int val = stackpop.top();
    54                 stackpop.pop();
    55                 return val;
    56         }
    57     }
    58 };
    59 
    60 int main()
    61 {
    62 
    63     return 0;
    64 }
  • 相关阅读:
    2010浙大:zoj问题
    Meta 数据中文显示
    django 中间件
    url的配置
    django.contirb
    os模块
    线程和异步
    ADO.NET
    C#托管代码 CLR
    C#垃圾回收
  • 原文地址:https://www.cnblogs.com/cane/p/3793568.html
Copyright © 2011-2022 走看看