Arista Networks Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
M Not Sure.. Why U think there is the limitation.
For Instance, if U find it difficult to implement generics in C. U should use void pointers.. all that template or generics can do is use an Abstract layer to make things easy.. but Finally U can do in C the same thing wat C++ or java Can Do..
I can write a Code of Stack / Queue or rather even a Vector in C using void pointer..
Yes; this is software and any abstractions can be derived and made available. My point was the ease of crafting code and implementation especially when objects of being interested tend to vary in sizes.
OTOH, my original response stands corrected. The reason for highlighting the last condition in the question meant to say that the age-old trick of embedding the insertion data structure into the original object would not work as it would be provide for a singular member of the original entity into stack from library aka., it does not allow the same original entity to be inserted into different stacks at the same simultaneously
Yes; this is software and any abstractions can be derived and made available. My point was the ease of crafting code and implementation especially when objects of being interested tend to vary in sizes.
OTOH, my original response stands corrected. The reason for highlighting the last condition in the question meant to say that the age-old trick of embedding the insertion data structure into the original object would not work as it would be provide for a singular member of the original entity into stack from library aka., it does not allow the same original entity to be inserted into different stacks at the same simultaneously
This is obvious question.
- hprem991 May 21, 20121> We need to use template class.
2> API's are very general API's like push /pop/top /size.
3> I would rather like to use Vector as it has the flexibility of resizing.
4> Yes, template class generates place holder's according to datatype and so it won't be an issue.
Implementation Fairly Easy
<template typename T>
class MyStack {
private :
vector <T> stack;
int size;
T *top;
public ;
bool Push ( T data)
{ }
T Pop()
{}
T Top()
{}
int Size()
{}
};
Now these API's are fairly easy to implement.