COMP 53 Midterm Two Spring Semester 2018 5) (16 Points) Assume that adaptation o
ID: 3701841 • Letter: C
Question
COMP 53 Midterm Two Spring Semester 2018 5) (16 Points) Assume that adaptation of the Node class used in lecture class Weblink you're given the following Weblink class, which is an the I private: string webAddress Link prev; public: Link NULL) Link(string a "http://www.goog string getaddress ) : Link getPrev) void setAddress(string a): void setPrev(Link p) eenting the Back button on a web browser. Unlike a normal stack, the Path class maintains a link to the bottom of the stack, which is the user's homepage. You're given the following partial implementation re writing the following Path class, which is a Stack of Weblink objects class Path t protected: // the top of the stack Weblink cur Weblink homepage: I the bottom of the stack Path() (cur homepage NULL: Write the push function to insert a new web address into the stack (there will be special cases because of the homepage link) public: a. void push (string webAddress)Explanation / Answer
a.
// push function to push the webAddress into the stack
void push(string webAddress)
{
// if homepage doesn't exist, create google.com as homepage
if(homepage == NULL){
homepage = new Weblink();
}
// if no cur page is null, make the new page as current page and set its previous pointing to homepage
if(cur == NULL)
{
cur = new Weblink(webAddress,homepage);
}else // create a new page with its previous pointing to current page and then make this new page as the current page
{
Weblink *newPage = new Weblink(webAddress,cur);
cur = newPage;
}
}
//end of push function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.