VMWare Inc Interview Question
Software Engineer / DevelopersYes it is, gurst :-)
Stack supports First in Last out operation. Two basic operations: Push and Pop.
Push puts an element on top and Pop removes the element from top.
Heavily used by compilers to support function calls, recursion etc.
Here is a C++ like skeleton implementation of stack using Linked List.
(fill in the details)
template <class T>
class Stack {
public Stack() {
InitializeLinkedList();
}
public Push(T obj) {
m_Head->InsertAtHead(obj);
}
public T Pop() {
T data = m_Head->GetData(obj);
tmp = m_Head;
m_Head = m_Head->Next();
delete tmp;
return data;
}
private:
LinkedList<T> *m_Head;
}
stack is type of data structure
- gurst March 19, 2009