Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Implementing BrowserHistory | Section
Practice
Projects
Quizzes & Challenges
Вікторини
Challenges
/
Fundamental Data Structures in Java

bookChallenge: Implementing BrowserHistory

Завдання

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.

Рішення

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 12
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

close

bookChallenge: Implementing BrowserHistory

Свайпніть щоб показати меню

Завдання

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.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 12
single

single

some-alt