Dequeue Class Queue Program ISC 2013 Theory

A doubly queue is a linear data structure which enables the user to add and remove integers from either ends, i.e. from front or rear. Define a class Dequeue with the following details:

Class name: Dequeue
Data members/instance variables:
arr[]: array to hold up to 100 integer elements.
lim: stores the limit of the dequeue.
front: to point to the index of front end.
rear: to point to the index of rear end.

Member functions:
Dequeue(int l): constructor to initialize data members lim = l; front = rear = 0.
void addFront(int val): to add integer from the front if possible else display the message “Overflow from front”.
void addRear(int val): to add integer from the rear if possible else display the message “Overflow from rear”.
int popFront(): returns element from front if deletion is possible from the front end, otherwise returns -9999.
int popRear(): returns element from rear if deletion is possible from the rear end, otherwise returns -9999.

Specify the class Dequeue giving details of the constructor, void addFront(int), void addRear(int), int popFront() and int popRear().

The main function and algorithm need not be written.

class Dequeue{
    int arr[];
    int lim;
    int front;
    int rear;
    public Dequeue(int l){
        lim = l;
        front = 0;
        rear = 0;
    }
    public void addFront(int val){
        if(front - 1 >= 0)
            arr[--front] = val;
        else
            System.out.println("Overflow from front");
    }
    public void addRear(int val){
        if(rear + 1 < lim)
            arr[++rear] = val;
        else
            System.out.println("Overflow from rear");
    }
    public int popFront(){
        if(front + 1 <= rear) 
            return arr[front--]; 
        return -9999; } 
    public int popRear(){ 
        if(rear - 1 >= front)
            return arr[rear--];
        return -9999;
    }
}

12 thoughts on “Dequeue Class Queue Program ISC 2013 Theory”

  1. Sir,a program is given which states that:
    WAP in java to accept some numbers to
    create m × m matrix(where m=size of the Matrix where m must be greater than 3 and less than 10).Display the elements above the right diagonal of that matrix.

  2. Sir,a program is given which states that:
    WAP in Java to find the Hailstone Sequence of a given number.The Hailstone sequence of numbers can be generated starting from an integer n by following these rule:
    If n =1,then the sequence ends.
    If n is even then the next n of the sequence=n/2
    If n is odd then the next n of the sequence=(3*n)+1
    Sample Input:
    Number:13
    Sample Output:
    The hailstone sequence starting from 13 is:
    40,20,10,5,16,8,4,2,1
    Without using any functions display the Hailstone sequence.Display an appropriate message if the number is<=0.

  3. Sir,2 programs are given which states that:
    1) WAP in Java to enter a natural number. Display all the possible combinations of the numbers which are added to give the sum equal to the original number.
    Sample Input:
    N=14
    Sample Output:
    1,2,5,6(i.e.1+2+5+6=14)
    2,3,9(i.e.2+3+9=14)
    3,5,6(i.e.3+5+6=14)
    5,9(i.e 5+9=14)
    1,13(i.e.1+13=14)
    2) WAP in java to accept some numbers to
    create m × m matrix(where m=size of the Matrix where m must be greater than 3 and less than 10).Display the elements above the right diagonal of that matrix.

  4. Sir,2 programs are given which states that:
    1) WAP in Java to find the Hailstone Sequence of a given number.The Hailstone sequence of numbers can be generated starting from an integer n by following these rule:
    If n =1,then the sequence ends.
    If n is even then the next n of the sequence=n/2
    If n is odd then the next n of the sequence=(3*n)+1
    Sample Input:
    Number:13
    Sample Output:
    The hailstone sequence starting from 13 is:
    40,20,10,5,16,8,4,2,1
    Use a recursive function that displays the Hailstone sequence if a number n is passed to it as a parameter.Display an appropriate message if the number is<=0.

    2) A class 'Composite' contains a two dimensional array of order[m x n].The maximum value possible for both 'm' and 'n' is 20.
    Design a class 'Composite' to fill the array with the first(m x n) composite numbers in column wise.The details of the members of the class are given below:
    Class name:Composite
    Data members/instance variables:
    arr[ ][ ]:stores the composite numbers column wise
    m : integer to store the number of rows
    n : integer to store the number of columns
    Member functions/methods:
    Composite(int mm,int nn) : to initialize the size of the matrix m=mm & n=nn
    int isComposite(int p): returns 1 if number is composite otherwise returns 0
    void fill():to fill the elements of thae array with the first(m x n) composite numbers in column wise.
    void display():displays the array in matrix form
    Specify the class Composite giving details of the constructor(int,int),int isComposite(int),void fill() and
    void display().Define a main() function to create an object and call the functions accordingly to enable the task.
    (ISC Specimen Paper-2020,Computer Science Paper 1(Theory))

      • Sir,2 programs are given which states that:
        1) WAP in Java to enter a natural number. Display all the possible combinations of the numbers which are added to give the sum equal to the original number.
        Sample Input:
        N=14
        Sample Output:
        1,2,5,6(i.e.1+2+5+6=14)
        2,3,9(i.e.2+3+9=14)
        3,5,6(i.e.3+5+6=14)
        5,9(i.e 5+9=14)
        2) WAP in java to accept some numbers to
        create m × m matrix(where m=size of the Matrix where m must be greater than 3 and less than 10).Display the elements above the right diagonal of that matrix.
        Sample Input:
        M=5
        Sample Input:
        22 14 23 61 25
        81 26 31 11 10
        58 64 17 27 12
        55 33 26 38 14
        21 36 54 63 48
        Sample Output:
        14 23 61 25
        31 11 10
        27 12
        14

        • For different combinations that sum up to a given number, why 13 + 1 = 14 is not included? The logic is not clear. Please elaborate on that.

        • Sir,a program is given which states that:
          WAP in Java to enter a natural number. Display all the possible combinations of the numbers which are added to give the sum equal to the original number.

Leave a Reply

%d bloggers like this: