Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

QUEUE operations using Array

C++ Program for the implementation of Linear Queue operation (insert, delete & display). C++ Program to implement QUEUE operations using Array. Queue is a abstract data type, In which entities are inserted into the rear end and deleted from the front end.
Queue based on the FIFO (First In First Out) criteria,means the element inserted first is get deleted first.

Source Code:-

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

int queue[100],front=-1,rear=-1,max;
void insert_element();
void delete_element();
void display_queue();


void main()
{ clrscr();
  int option;
  cout<<"Implement Queue operations by-Tarun Rawat\n\n";
  cout<<"Enter the size of Queue : ";
  cin>>max;
  do
  {cout<<"1.Insert an element";
   cout<<"\n2.Delete an element";
   cout<<"\n3.Display queue";
   cout<<"\n4.Exit";
   cout<<"\nEnter your choice : ";
   cin>>option;
   switch(option)
   { case 1: insert_element();
          break;
     case 2: delete_element();
         break;
     case 3: display_queue();
         break;
     case 4: return 0;
   }
 }while(option!=4);

getch();
}


void insert_element()
{
  int num;
  cout<<"\nEnter the item to be inserted : ";
  cin>>num;
  if(front==0 && rear==max-1)
    cout<<"\nQueue OverFlow Occured\n";
  else if(front==-1&&rear==-1)
  {
      front=rear=0;
      queue[rear]=num;

  }
  else if(rear==max-1 && front!=0)
  {
    rear=0;
    queue[rear]=num;
  }
  else
  {
      rear++;
      queue[rear]=num;
  }
}
void delete_element()
{
  int element;
  if(front==-1)
  {
      cout<<"\nUnderflow\n";
  }
  element=queue[front];
  if(front==rear)
     front=rear=-1;
  else
  {
    if(front==max-1)
      front=0;
    else
      front++;
       cout<<"\nThe deleted element is : "<<element;
  }

}
void display_queue()
{
    int i;
    if(front==-1)
      cout<<"\nNo elements to display";
    else
    {
      cout<<"\nThe queue elements are :\n";
      for(i=front;i<=rear;i++)
      {
      cout<<"\t"<<queue[i];
      }
    }
}

5 comments:

  1. I always Get Bored with the coding. you Provide Amazing Information. It really Helpful. Much Doubt Clear reading this.

    ReplyDelete
  2. Great article thanks for sharing
    check it also
    https://apkdestiny.com/freestore-apk/

    ReplyDelete

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)