In any internet browser, a user can visit new webpages and go back to previously visited webpages…
In any internet browser, a user can visit new webpages and go back to previously visited webpages. Each new webpage URL is stored in browser's memory such that when the user clicks 'Back' button, the previous webpage gets displayed.
The details of the members of the class are given below:
Class name : Browser
Data members/instance variables:
pages[ ] : an array to hold the URLs of visited webpages
max : to store the maximum capacity of the array
top : to point to the index of the last visited webpages
Methods/Member functions:
Browser(int cap) : constructor to assign max = cap and top = -1
void visit(String url) : to add URL of a new webpage if possible, else display the message "Browser history full"
String back( ) : to remove and return the last visited webpage URL, if present, else to return the message "No previous browser history"
(i)[4.0]
Specify the class Browser giving details of the functions void visit(String) and String back( ). Assume that the other functions have been defined.
(ii)[1.0]
Name the entity described above and state its principle.
Answer
Answer (i)
AIWritten by AI (antigravity) - it can contain mistakes.
void visit(String url)
{
if (top == max - 1)
{
System.out.println("Browser history full");
}
else
{
top++;
pages[top] = url;
}
}
String back()
{
if (top == -1)
{
return "No previous browser history";
}
else
{
String url = pages[top];
top--;
return url;
}
}Answer (ii)
AIWritten by AI (antigravity) - it can contain mistakes.
Entity name: Stack
Principle: LIFO (Last In, First Out). The most recently visited URL added to the stack is the first one retrieved when navigating back.
From ISC 2026 Computer Science Paper 1, question 9.