हिंदी

In any internet Each browser, new webpage a user can visit new webpages and go back to previously visited URL is stored in browser’s memory such that when the user clicks

Advertisements
Advertisements

प्रश्न

In any internet Each browser, new webpage a user can visit new webpages and go back to previously visited 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 webpage
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”

  1. Specify the class Browser, giving details of the functions void visit(String) and String back(). Assume that the other functions have been defined.
  2. Name the entity described above and state its principle.
कोड लेखन
लघु उत्तरीय
Advertisements

उत्तर

  1. Implementation of functions:
    void visit(String url) {
        if (top == max - 1) {
            System.out.println("Browser history full");
        } else {
            pages[++top] = url;
        }
    }
    String back() {
        if (top == -1) {
            return "No previous browser history";
        } else {
            return pages[top--];
        }
    }
  2. Entity and Principle:
    • Entity Name: Stack
    • Principle: LIFO (Last-In, First-Out)
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2025-2026 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×