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

bookChallenge: Implementing BrowserHistory

Tarea

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.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 12
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

close

bookChallenge: Implementing BrowserHistory

Desliza para mostrar el menú

Tarea

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.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 12
single

single

some-alt