Question: use doubly linked list complete browserhistory.cpp browserhistory.cpp #include browserhistory.h BrowserHistory::BrowserHistory(string default_url) { // Creates a new browser history with only one page visited: default_url Node*
use doubly linked list
complete browserhistory.cpp
browserhistory.cpp
#include "browserhistory.h" BrowserHistory::BrowserHistory(string default_url) { // Creates a new browser history with only one page visited: default_url Node* temp = new Node(); temp->url = default_url; temp->next = temp->prev = nullptr; head = tail = current = temp; // have one website only (defult_url) } string BrowserHistory::current_url() { // Returns the current page. } void BrowserHistory::go_to_url(string url) { // Moves the browser to a new page url via, // enters a new url (new Node in the linked list) } void BrowserHistory::back() { // Moves back (into the past) by one url. // check first if it can go back before it actually goes back } void BrowserHistory::forward() { // Moves forward (into the future) by one url. // Check if can_go_forward is true in order to actually move forward. } bool BrowserHistory::can_go_back() { // Returns whether there is a url in the past, // i.e. whether the back button can be pushed. } bool BrowserHistory::can_go_forward() { // Returns whether there is a url in future, // i.e. whether the future button can be pushed. } int BrowserHistory::past_url_count() { // Returns how many urls are in the past, // i.e. how many times in a row the back button could be pushed. //i.e. how many nodes are behind the current node } int BrowserHistory::future_url_count() { // Returns how many urls are in the future, // i.e. how many times in a row the forward button could be pushed. //i.e. how many nodes are infront of the current node } //Bonus Point void BrowserHistory::empty_browser() { //go through the linked list and release the memory } browserhistory.h
#ifndef BROWSERHISTORY_H #define BROWSERHISTORY_H #includeusing namespace std; class BrowserHistory { public: // Creates a new browser history with only one page visited: default_url BrowserHistory(string default_url); // Returns the current page. string current_url(); // Moves the browser to a new page url via, // e.g., clicking a link, typing into the address bar, etc. void go_to_url(string url); // Moves back (into the past) by one url. void back(); // Returns whether there is a url in the past, // i.e. whether the back button can be pushed. bool can_go_back(); // Returns how many urls are in the past, // i.e. how many times in a row the back button could be pushed. int past_url_count(); // Moves forward (into the future) by one url. void forward(); // Returns whether there is a url in future, // i.e. whether the future button can be pushed. bool can_go_forward(); // Returns how many urls are in the future, // i.e. how many times in a row the forward button could be pushed. int future_url_count(); //Bonus Point void empty_browser(); private: class Node { public: string url; Node* next; Node* prev; }; // A head and a tail pointer Node* head; Node* tail; Node* current; }; #endif
Source.cpp
#include#include "browserhistory.h" int main() { // History: [(google.com)] BrowserHistory bh("http://google.com"); cout << bh.current_url() <
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
