icse-promo

Question

A linear data structure enables the user to add address from rear end 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

(a)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.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					class Diary
{ 
    String Q[];
    int size, start, end;

    void pushadd(String n)
    {
        if(end< size)
        {
            Q[end]=n;
            end=end+1;
        }
        else
        {
            System.out.println(" NO SPACE");
        }
    }
    
    String popadd()
    {
        if(start!=end)
        {
            return Q[start++];
         
        }
        else
        {
            return "?????";
        } 
    }
}

				
			

Leave a Reply

Your email address will not be published. Required fields are marked *