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

bookChallenge: Implementing BrowserHistory

Tâche

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.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 12
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookChallenge: Implementing BrowserHistory

Glissez pour afficher le menu

Tâche

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.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 12
single

single

some-alt