DEQUEUE

DEQUEUE

HOME

/*
PROGRAM FOR ENQUEUEING THE ELEMENTS

 
USING SELF  REFERENTIAL CLASSES   */

#include”iostream.h”

class
queue  //NAME
OF THE CLASS

{
private:     //DATA MEMBERS
  
 int data;

  
 queue *next;

public:  //MEMBER
FUNCTIONS       

  
 int dequeue();

  
 void enqueue(int);  

   
void display();

}
*head; //OBJECT ACTS
AS NODE

//FUNCTION
DECLARATION

void
queue::enqueue(int ele)
{
  
 queue *n,*temp;

   
n=new(queue);  
//MEMORY ALLOCATION

  
 n->data=ele;

  
 n->next=NULL;

//IF
THE LIST IS EMPTY THEN ADD

//1st
NODE AS HEADER NODE

      
if(head==NULL)

  
     head=n;

  
 else

  
 {

  
 temp=head;

  
 while(temp->next!=NULL)

  
 temp=temp->next;

  
  temp->next=n;

  
 }

}
//FUNCTION
FOR DEQUEUEING

int
queue::dequeue()

{
  
 queue *temp;

  
 if(head==NULL)

  
 cout<<“QUEUE IS EMPTY:”;

  
 else

  
 {

  
 temp=head;

  
 head=temp->next;

  
 delete temp;

  
     

  
 }

  
 return(0);

}

//DISPLAY
THE RESULT

void
queue::display()

{
queue 
*temp;

  
 

  
 if(head==NULL)

  
 cout<<” EMPTY\n”;

  
 else

  
 {

  
 temp=head;

  
 while(temp!=NULL)

  
 {

  
         

  
 cout<<temp->data<<endl;

  
 temp=temp->next;

  
 }

  
 }

}

void
main() //main()
FUNCTION STARTS

{
  //INITIALIZATION OF HEADER
NODE

 
head=NULL;

queue
l;//OBJECT OF THE
CLASS List

  
 int x,a[20];

cout<<“ENTER
THE NO OF

     
ELEMENTS TO BE ENQUEUED\n”;

  
 cin>>x;

 cout<<“ENTER
“<<x<<“ELEMENTS\n”;

  
 for(int i=0;i<x;i++)

  
 {

  
     cin>>a[i];

//PASING
THE ELEMENTS TO THE

//
FUNCTION THROUGH OBJECT

    
l.enqueue(a[i]);

  
 }

  
 cout<<“THE LIST IS\n”;

 //CALLING
FUNCTION TO DISPLAY

//RESULT
THROUGH OBJECT

l.display();

  
 for(int j=0;j<x;j++)

  
 {

  
 l.dequeue();

cout<<“AFTER
DELETING THE FRONT

      
END “<<a[j]<<” THE QUEUE IS\n”;

  
 l.display();

  
 }

}

//PROGRAM
ENDS

/*
OUTPUT:

 
ENTER THE NO OF
ELEMENTS TO BE ENQUEUED

5
ENTER
5ELEMENTS

12
34
45
67
89
THE
LIST IS

12
34
45
67
89
AFTER
DELETING THE FRONT

        
END 12 THE QUEUE IS

34
45
67
89
AFTER
DELETING THE FRONT

        
END 34 THE QUEUE IS

45
67
89
AFTER
DELETING THE FRONT

         
END 45 THE QUEUE IS

67
89
AFTER
DELETING THE FRONT

        
END 67 THE QUEUE IS

89
AFTER
DELETING THE FRONT

       
END 89 THE QUEUE IS

 EMPTY
Press
any key to continue

*/

HOME

Advertisements

2 Comments »

  1. 1
    E.SURENDRA Says:

    you have done anice job

  2. 2
    Anil CSE Says:

    good


RSS Feed for this entry

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: