हिंदी

A double ended queue is a linear data structure which enables the user to add and remove integers from either ends i.e., from front or rear.

Advertisements
Advertisements

प्रश्न

A double ended queue is a linear data structure which enables the user to add and remove integers from either ends i.e., from front or rear.

The details for the class deQueue are given below:

Class name deQueue

Data members/instance variables:

Qrr[] array to hold integer elements
lim maximum capacity of the dequeue
front to point the index of the front end
rear  to point the index of the rear end

Methods/Member functions:

deQueue(int 1) constructor to initialise lim = 1, front = 0 and rear =0
void addFront(int v) to add integers in the dequeue at the front end if possible, otherwise display the message “OVERFLOW FROM FRONT”
void addRear(int v) to add integers in the dequeue at the rear end if possible, otherwise, display the message “OVERFLOW FROM REAR”
int popFront() removes and returns the integers from the front end of the dequeue if any, else returns — 999
int popRear ( )  removes and returns the integers from the rear end of the dequeue if any, else returns — 999
void show( ) displays the elements of the dequeue

Specify the class deQueue giving details of the function void addFront(int) and int popFront(). Assume that the other functions have been defined. The main() function and algorithm need NOT be written.

संक्षेप में उत्तर
Advertisements

उत्तर

class deQueue
{
int Qarr[];
int lim;
int front;
int rear;
public deQueue(int l)
{
   lim=l;
   front=-1;
   rear=-1;
   Qarr[]=new Qarr[l];
}
public void addFront(int v)
{
   if((front=0 && rear=lim-1) || (front=rear+1))
      System.out.println(“Overflow from front”);
  else if((front=-1) && (rear=-1))
  { front=rear=0;
     Qarr{front]=v;
 }
 else if (front=0)
 {  front=lim-1;
    Qarr{front]=v;
       }
  else
  {
     front=front-1;
    Qarr[front]=v;
    }
}
    public void popFront()
   {
        if((front=-1) &&c (rear=-1))
           {
              System.out.println(“Deque is empty”);
           }
     else if(front=rear)
     {
        System.out.println(“The deleted element is :”,
        Qarr[front]);
        front=-1;
        rear=-1;
     }
     else if(front=(size-1))
     {
        System.out.println(“The deleted element is :",
        Qarr[front]);
        front=0;
    }
    else
    {
       System.out.println(“The deleted element is :",
       Qarr[front]);
       front=front+1;
     }
  }
}
shaalaa.com
Basic Data Structures (Stack, Queue, Dequeue)
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2022-2023 (March) Official

संबंधित प्रश्न

What is Data Structure? 


Define:

(i) Tree

(ii) Binary Tree

(iii) Extended Binary


Write an algorithm for the binary search method. Explain algorithm with a suitable example.


With suitable example explain how tree can be represented in Memory?


What is a linked list?


State algorithm for inserting an element in an Array.


Explain with a flowchart the following control structure:

Selection Logic


write difference between Linear Search and Binary Search.


Define the following term with reference to the Tree:

Depth


Write an algorithm for Traversing Linear Array.


Define Entity.


What is Record?


Explain how records are represented in memory using an array?


Explain Binary Scarch algorithm with a suitable example.


What is Binary Tree ? Draw the Tree diagram for the expression. 
B = (3R -5T)2 - (R + Q3)


 Explain memory representation of linked list with example.


State the principle by which the stack data structure works.


A Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out).

Define a class Queue with the following details:

Class name Queue
Data member/instance variable:
dat[ ] array to hold the integer elements
cap stores the maximum capacity of the queue
front to point the index of the front
rear to point the index of the rear
Member functions/methods:
Queue(int max) constructor to initialize the data member cap = max, front = rear = 0 and create the integer array
void add_dat(int v) to add integers from the rear index if possible else display the message(“Queue full”)
int pop_dat( ) to remove and return elements from front, if any, else returns -999
void display() to display elements of the queue

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

The main( ) function and algorithm need NOT be written.


Differentiate between a stack and a queue.


Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×