Pregunta de entrevista de ServiceNow

Reverse a stack wothout using any other data structure

Respuestas de entrevistas

Anónimo

2 de ago de 2018

If a stack is implemented using linked list we can keep track of head and tail nodea and an auxiliary node that srores tail. Move all the nodes 4m head to tail until we visit the tail that we stored in auxiliary node. Note that while replacing the nodes put them after the initial tail node but not after the actual tail

1

Anónimo

2 de ago de 2018

If a stack is implemented using linked list we can keep track of head and tail nodea and an auxiliary node that srores tail. Move all the nodes 4m head to tail until we visit the tail that we stored in auxiliary node. Note that while replacing the nodes put them after the initial tail node but not after the actual tail

1

Anónimo

31 de dic de 2018

Using another stack along with the first stack effectively reverses the first stack ,pop and peek are exposed on second stack while push is overridden so everytime a push is done on first stack it's popped and pushed on to second stack,. Long story short - reverse of a stack is queue and we can implement a queue with 2 stacks without any other data structure apart from stack