If you were asked to design the backward and forward button operation (as a library) in a browser, how would you do it? What will be your APIs and parameters to them? what data structure will be best suitable for this usecase?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Simplest solution would be to use two stacks (back, forward).
Clicking the back button will pop from the back stack and push the current page on the forward stack (and go to the popped value on the back stack).
Clicking on any link on a page (following a link) will clear the forward stack and push the current page on the back stack.
Clicking on the forward button will pop from the forward stack and push the current page on the back stack (and go to the popped value on the forward stack).
The back and forward buttons are disabled when the appropriate stack is empty.
I would use an array containing urls, with a variable storing the length and an index pointing to the current item being displayed.
Back decrements the index, Forward increments the index. New page increments the index, stores the url at that place in the array and sets the length to the index value.
When the array is full, I would either use a