Queue Program ISC 2017

Queue is an entity which can hold a maximum of 100 integers. The queue enables the user to add integers from the rear and remove integers from the front.

Define a class Queue with the following details:

Class name: Queue
Data members/instance variables:
que[]: array to hold the integer elements.
size: stores the size of the array.
front: to point to the index of the front.
rear: to point to the index of the rear.
Member functions:
Queue(int m): constructor to initialize the data size the data size = m, front = 0, rear = 0.
void addElement(int v): to add integer from the rear if possible, else display the message “Overflow”.
int delete(): returns elements from front if present, otherwise displays the message “Underflow” and returns -9999.
void display(): displays the array elements.

Specify the class Queue giving details of only the functions void addElement(int) and int delete(). Assume that the other functions have been defined.

The main function and algorithm need not be written.

class Queue{
    public void addElement(int v){
        if(rear + 1 < size)
            que[++rear] = v;
        else
            System.out.println("Overflow");
    }
    public int delete(){
        int d = que[front];
        if(front == 0 && rear == 0){
            System.out.println("Underflow");
            return -9999;
        }
        else{
            front++;
            if(front > rear)
                front = rear = 0;
            return d;
        }
    }
}

6 thoughts on “Queue Program ISC 2017”

  1. Sir,3 questions are given which states that:
    A linked list is formed from the objects of the class:
    class Node{
    int num;
    Node next;
    }
    Write anAlgorithm OR aMethodto insert anodeat the beginning ofan existinglinked list.The method declaration is as follows:void InsertNode( Nodes starPtr, int n )

    Design a classSort which enables a word to be arranged in alphabetical order.The details ofthe members of the class are given below :
    Class name :SortData
    members /instance variables:Str:stores a word len : to store the length of the word
    Member functions :
    Sort( ): default constructor
    void readword( ) : to accept the word
    void arrange ( ) : to arrange the word in alphabetical order using anystandard sorting technique.
    void display( ) : displays theoriginal word along with the sortedword
    Specify the classSortgiving details of theconstructor,void readword( ), void arrange( ),and void display( ).Definethemain( )function to create an object and call the functionsaccordinglyto enable the task.

    A Special number is a number in which the sum of the factorial of its digits is equal to thenumber. Example: 145 ( 1! + 4! + 5! = 145 ). Thus, 145 is a special number.Design a classSpecialtocheck if the givennumber is a Special number or not.Some of the membersof the classare given below:
    Class name :Special
    Data members /instance variables :n: integer to store the number
    Member functions :Special( ):default constructor
    void read( ):to accept thenumberint factorial(int x):return the factorial of a number usingrecursion technique.
    boolean isSpecial( ):checks for the special number by invoking the functionfactorial( ) and returns true if Special, otherwise returns false
    void display( ):to show the resultwith an appropriate message.
    Specify the classSpecial, giving details of theConstructor,voidread( ), int factorial(int),booleanisSpecial( ) and void display( ). Definethemain()function to create an object and call the member function according to enable the task.

    Reply
  2. A linked list is formed from the objects of the class Node. The class structure of the Node is given below:
    class Node {
    int num; Node next;
    }
    Write an Algorithm OR a Method to count the nodes that contain only odd integers from an existing linked list and returns the count. The method declaration is as follows: int CountOdd( Node startPtr )

    Reply
    • int countOdd(int startPtr){
      if(startPtr == null)
      return 0;
      else if(startPtr.num % 2 == 1)
      return 1 + countOdd(startPtr.next);
      else
      return coundOdd(startPtr.next);
      }

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: