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
Solução
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Incrível!
Completion taxa melhorada para 6.25
Challenge: Implementing BrowserHistory
Deslize para mostrar o menu
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
Solução
Obrigado pelo seu feedback!
single