Bloomberg L.P.
3.2 of 5 1,100 reviews
www.bloomberg.com New York, 061 5000+ Employees

Bloomberg L.P. Financial Applications Engineer Interview Question

I interviewed in New York, NY and was asked:
"How to implement a queue using a stack"
Add Tags [?]
Answer Flag Question

Part of a Financial Applications Engineer Interview Review - one of 1,717 Bloomberg L.P. Interview Reviews

Answers & Comments

0
of 0
votes
#include <iostream>
#include <stack>
#include <queue>
/*
Interview Question for Financial Applications Engineer at Bloomberg L.P.: Sep 17, 2013
How to implement a queue using a stack
*/

using namespace std;

class MyQueue {
public:
    void push(int data) {
        if (_queue.empty()) {
            _queue.push(data);
        } else {
            int backupTop = _queue.top();
            _queue.pop();
            push(data);
            _queue.push(backupTop);
        }
    }
    void pop() {
        if (!_queue.empty()) return _queue.pop();
    }
    int front() {
        return _queue.top();
    }
private:
    std::stack<int> _queue;
};

int main() {

    MyQueue myqueue;
    std::queue<int> queue;

    const int MAX_DATA_SIZE = 9;
    int data[MAX_DATA_SIZE] = {1,2,3,4,5,6,7,8,9};

    for (int i = 0 ; i < MAX_DATA_SIZE ; i++) {
        myqueue.push(data[i]);
        queue.push(data[i]);
    }

    for (int i = 0 ; i < 2 ; i++) {
        myqueue.pop();
        queue.pop();
    }

    cout << "My queue front: " << myqueue.front() << endl;
    cout << "std queue's front: " << queue.front() << endl;

    return 0;
}
- Juan Andrango on Sep 27, 2013 Flag Response

To comment on this question, Sign In with Facebook or Sign Up


Bloomberg L.P. – Why Work for Us?

Bloomberg’s global mission is to help individuals, enterprises and governments make smarter, faster, more profitable decisions — first. In order to get there, we need constant ideas, energy, innovation— which is where… Full Overview

Provided by employer [?]

Tags are like keywords that help categorize interview questions that have something in common.

Glassdoor is your free inside look at Bloomberg L.P. interview questions and advice. All interview reviews posted anonymously by Bloomberg L.P. employees and interview candidates.