Bloomberg LP Interview Question
Software Engineer / Developersfor #1 1st part
use
#ifdef cplusplus
extern "C"{
#endif
/*your C code*/
#ifdef cplusplus
}
#endif
For Q 4:
In order to use object as key in a Map , class must overload '>' operator.
So that comparison of objetcs can be done.
Hey,guys I am preparing for Bloomberg can anyone suggest some good C++ books for it. SInce Bloomberg puts a lot of emphasis on C++ knowledge .
I belive that question 3 was in other words question if the class with 1 object have automatically overloaded operator < based on this single element. Turns out it doesn't, example code:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class my_class{
public:
int x;
};
bool operator<(const my_class& a, const my_class& b) {
return a.x < b.x;
}
vector<my_class> v;
int main() {
sort(v.begin(), v.end());
}
Try to compile this code without the line:
bool operator<(const my_class& a, const my_class& b);
And see how it fails.
2. Compiler compiles the class file anyway, but does not assign any memory (I think the next question determines why this is the answer that was being expected).
3. When the object is created, memory is assigned to the object.
What the interviewer probably expected from the second part of the question was whether the objects could be ordered based on some property/variable. In Java, we can use the Comparable interface to achieve this.
4. Yes, if we use a sorted map (such as TreeMap, again, Java).
5. By default, a map is not sorted. But a sorted Map such as TreeMap is sorted based on the key.
Hope this helps.
Re: #6 - no other solution posted has tried to preserve the order of the list. In case that matters, copy the data from 6 -> 5, from 7 -> 6 etc, and when you reach the last node, delete it (because you've kept two ptrs, a 'current' and 'next'). This list will be identical to just having removed the 5th element. (Unless some outside code has a ptr to an elts of the list.)
Is this a direct interview or did you give any test before it
- Newbie December 09, 2010