セクション 1. 章 12
single
Challenge: Implementing BrowserHistory
メニューを表示するにはスワイプしてください
タスク
スワイプしてコーディングを開始
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
解答
すべて明確でしたか?
フィードバックありがとうございます!
セクション 1. 章 12
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください