DreamsCoder.com

We Code your Dreams


home > Dynamic Queue program using C++




Dynamic Queue program using C++







This is Dynamic Queue program implemented using C++
Function are

  • 1. INSERT
  • 2. DELETE
  • 3. DISPLAY
  • 4. EXIT

    /*
    Title - Dynamic Queue program
    Author - Chinmay Mahajan 
    */
    #include
    #include
    #include
    
    class dqueue
    {
    	struct node
    	{
    		int data;
    		node *next;
    
    	}*front,*rear,*temp;
    	public: dqueue()
    		{
    		front=NULL;
    		rear=NULL;
    		}
    		void add();
    		void del();
    		void display();
    };
    void dqueue::add()
    {
    	temp=new node();
    
    	cout<<"Enter the Data \t";
    	cin>>temp->data;
    
    	if(front==NULL)
    	{
    		front=temp;
    		rear=temp;
    	}
    	else
    	{
    	temp->next=NULL;
    	rear->next=temp;
    	rear=temp;
    
    	}
    
    
    } //add()
    
    void dqueue::del()
    {
    temp=new node();
    temp=front;
    if(front==NULL)
    {
    cout<<"No Data Found";
    }
    else
    {
    front=front->next;
    delete temp;
    cout<<"Deleted Successfully";
    }//else
    }//delete
    
    void dqueue::display()
    {
    	temp=new node();
    	temp=front;
    
    	while(temp!=NULL)
    	{
    		cout<data;
    		temp=temp->next;
    	}
    }
    void main()
    {
    	clrscr();
    	dqueue d;
    	int ch;
    	do
    	{
    	cout<<"\n1.Insert\n2.Delete\n3.Display
    \n4.Exit\t";
    	cin>>ch;
    	switch(ch)
    	{
    	case 1:d.add();
    		break;
           case 2:d.del();
    		break;
    	case 3:d.display();
    		break;
    	case 4: exit(0);
    	default: cout<<"Incorrect Input";
    	}
           }while(ch!=4);
    
    }

    Label - data-structure





    by - Chinmay Mahajan





  • Are you looking for something else?


    Suggested Programs




    Simple code in C for Binary tree traversal: Preorder, Inorder and Postorder


    Printing the singly linked list in reverse order using recursion in C


    Singly Link List program in C along with code - [Explained in Video]


    Breadth first search in C Language


    Program To show whether expression have matching parenthesis or not using C++