Microsoft Interview Question
Software Engineer in Testssize command gives the size of an object file after compilation( not at runtime) in linux . But the question is :run time stack.I think we have to use any psuedo file system like "proc" in linux distros. There associated with process id (which we can get using getpid()) and at all if we have permission to access /proc/"pid" directory then we can almost get any information related to process memory. Any suggestions are welcome.
Change the stack structure by adding a an extra element for saving stack size, somthing like
struct stackelement
{
int stackLen;
blah blah
stackelement *next;
}
every time you push a element do the following
a) pop a element read the stack size
b) push the element
c) increase the stack size and embed in the new item to pushed
to get the stack size
a) pop a element and read stack size
b) push the element back to stack
complexity is O(1)
disadvantage relatively more memory than usual stack.
Change the stack structure by adding a an extra element for saving stack size, somthing like
struct stackelement
{
int stackLen;
blah blah
stackelement *next;
}
every time you push a element do the following
a) pop a element read the stack size
b) push the element
c) increase the stack size and embed in the new item to pushed
to get the stack size
a) pop a element and read stack size
b) push the element back to stack
complexity is O(1)
disadvantage relatively more memory than usual stack.
through sizeof(struct stack) and then finding out how many nodes are there in stack. I think this would work
- Aditya June 07, 2011