Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Implementing BrowserHistory | Section
Practice
Projects
Quizzes & Challenges
Quizzen
Challenges
/
Fundamental Data Structures in Java

bookChallenge: Implementing BrowserHistory

Taak

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.

  1. In the visit(String url) method:

    • Add the currentPage to the backStack.
    • Update currentPage to the new url.
    • Clear the forwardStack to reset forward history.
  2. In the back(int steps) method:

    • The loop should continue while steps > 0 and backStack is not empty.
    • Push the currentPage onto the forwardStack.
    • Pop the last page from the backStack and assign it to currentPage.
    • After moving backward, return the currentPage.
  3. In the forward(int steps) method:

    • The loop should continue while steps > 0 and forwardStack is not empty.
    • Push the currentPage onto the backStack.
    • Pop the last page from the forwardStack and assign it to currentPage.
    • After moving forward, return the currentPage.
  4. In the getCurrentPage() method:

    • Simply return the currentPage.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 12
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

close

bookChallenge: Implementing BrowserHistory

Veeg om het menu te tonen

Taak

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.

  1. In the visit(String url) method:

    • Add the currentPage to the backStack.
    • Update currentPage to the new url.
    • Clear the forwardStack to reset forward history.
  2. In the back(int steps) method:

    • The loop should continue while steps > 0 and backStack is not empty.
    • Push the currentPage onto the forwardStack.
    • Pop the last page from the backStack and assign it to currentPage.
    • After moving backward, return the currentPage.
  3. In the forward(int steps) method:

    • The loop should continue while steps > 0 and forwardStack is not empty.
    • Push the currentPage onto the backStack.
    • Pop the last page from the forwardStack and assign it to currentPage.
    • After moving forward, return the currentPage.
  4. In the getCurrentPage() method:

    • Simply return the currentPage.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 12
single

single

some-alt