Diary Class Queue Program ISC 2019 Theory

A linear data structure enables the user to add address from rear and remove address from front. Define a class Diary with the following details:

Class name: Diary
Data members/instance variables:
q[]: array to store the addresses.
size: stores the maximum capacity of the array.
start: to point the index of the front end.
end: to point the index of the rear end.
Member functions:
Diary(int max): constructor to initialize the data member size = max, start = 0 and end = 0.
void pushAdd(String n): to add address in the diary from the rear end if possible, otherwise display the message “NO SPACE”.
String popAdd(): removes and returns the address from the front end of the diary if any, else returns “?????”.
void show(): displays all the addresses in the diary.

  1. Specify the class Diary giving details of the functions void pushAdd(String) and String popAdd(). Assume that the other functions have been defined.
    The main() function and algorithm need not be written.
  2. Name the entity used in the above data structure arrangement.

 

class Diary{
    public void pushAdd(String n){
        if(q[0].equals(""))
            q[0] = n;
        else if(rear + 1 < size) 
            q[rear + 1] = n; 
        else 
            System.out.println("NO SPACE"); 
    } 
    public String popAdd(){ 
        if(front - 1 >= 0)
            return q[front--];
        else
            return "?????";
    }
}

The entity used in the above data structure argument is Queue.

Leave a Reply