Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Data File StructureRSS Feeds

Program to create queue / fifo using dynamic memory allocation

Posted By: Easy Tutor     Category: C++ Programming     Views: 9108

Write a Program to create queue / fifo using dynamic memory allocation and perform below functionalities

1) Insert Element
2) Delete Element

Code for Program to create queue / fifo using dynamic memory allocation in C++ Programming

#include <iostream.h>
#include <conio.h>

struct queue
{
 int data;
 struct queue *next;
};

staticint top=-1;
queue *head=NULL;

void insert(void)
{
  if(top==-1)
    cout<<"\n\nList is Empty\n";
  if(top>=9)
  {
    cout<<"\n\nList Overflow\n";
    gotoout;
  }
  else
  {
  queue *newl;
   newl=new queue;
   cout<<"\n\nEnter your Data :- ";
   cin>>newl->data;
   if(head==NULL)  //If head is Null inserting at first position
   {
     newl->next=head;
     head=newl;
   }
   else//Inserting at Last Position
   {
     queue *count=head;
       while(count->next!=NULL)
         count=count->next;
     count->next=newl;
     newl->next=NULL;
   }
   top=top+1;
   }
out:
}

void del(void)
{
  if(top<0)
  {
    cout<<"\n\nList Underflow\n";
    gotoout;
  }
  else
  {
   queue *temp;
   cout<<"\n\nData Which was Deleted was "<<head->data;
   temp=head;
   head=head->next;
   delete(temp);
   top=top-1;
  }
out:
}

void main()
{
 clrscr();
 int choice;
  while(1)
  {
   cout<<"\n\n\nChoose your choice\n";
   cout<<"1) Insert\n";
   cout<<"2) Delete\n";
   cout<<"3) Exit\n";
   cout<<"Enter your  choice :- ";
   cin>>choice;
    switch(choice)
    {
      case 1 : insert();
               break;
      case 2 : del();
               break;
      case 3 : gotoout;
      default: cout<<"\n\nEnter choice is Invalid\nTry Again\n\n";
    }
  }
out:
}
  
Share: 



Easy Tutor
Easy Tutor author of Program to create queue / fifo using dynamic memory allocation is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Kumeran Siva from Malaysia Comment on: Apr 10
1>asd - 18 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This codes are having errors and im a beginer i dont know what to do
i have to execute a Queue (FIFO) program for my assignment and i have to submit tomoorw, cud u help me out?

View All Comments