Challenge: Implementing BrowserHistory
Swipe to start coding
In this task, you need to complete the BrowserHistory class by filling in the missing parts. The goal is to implement a basic browser history system using two stacks: one for back navigation (backStack) and one for forward navigation (forwardStack).
You will handle visiting new pages, moving backward and forward through history, and keeping track of the current page. Use Deque.
-
In the
visit(String url)method:- Add the
currentPageto thebackStack. - Update
currentPageto the newurl. - Clear the
forwardStackto reset forward history.
- Add the
-
In the
back(int steps)method:- The loop should continue while
steps > 0andbackStackis not empty. - Push the
currentPageonto theforwardStack. - Pop the last page from the
backStackand assign it tocurrentPage. - After moving backward, return the
currentPage.
- The loop should continue while
-
In the
forward(int steps)method:- The loop should continue while
steps > 0andforwardStackis not empty. - Push the
currentPageonto thebackStack. - Pop the last page from the
forwardStackand assign it tocurrentPage. - After moving forward, return the
currentPage.
- The loop should continue while
-
In the
getCurrentPage()method:- Simply return the
currentPage.
- Simply return the
Solución
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Genial!
Completion tasa mejorada a 6.25
Challenge: Implementing BrowserHistory
Desliza para mostrar el menú
Swipe to start coding
In this task, you need to complete the BrowserHistory class by filling in the missing parts. The goal is to implement a basic browser history system using two stacks: one for back navigation (backStack) and one for forward navigation (forwardStack).
You will handle visiting new pages, moving backward and forward through history, and keeping track of the current page. Use Deque.
-
In the
visit(String url)method:- Add the
currentPageto thebackStack. - Update
currentPageto the newurl. - Clear the
forwardStackto reset forward history.
- Add the
-
In the
back(int steps)method:- The loop should continue while
steps > 0andbackStackis not empty. - Push the
currentPageonto theforwardStack. - Pop the last page from the
backStackand assign it tocurrentPage. - After moving backward, return the
currentPage.
- The loop should continue while
-
In the
forward(int steps)method:- The loop should continue while
steps > 0andforwardStackis not empty. - Push the
currentPageonto thebackStack. - Pop the last page from the
forwardStackand assign it tocurrentPage. - After moving forward, return the
currentPage.
- The loop should continue while
-
In the
getCurrentPage()method:- Simply return the
currentPage.
- Simply return the
Solución
¡Gracias por tus comentarios!
single