Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Implementing BrowserHistory | Section
Fundamental Data Structures in Java

bookChallenge: Implementing BrowserHistory

Tehtävä

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.

Ratkaisu

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 12
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

close

bookChallenge: Implementing BrowserHistory

Pyyhkäise näyttääksesi valikon

Tehtävä

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.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 12
single

single

some-alt