Queues Using Array

Praktek Mata Kuliah Data Structure

Queues on Array using DevC++


#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define n 6

int array [n];
int front=-1;
int rear=-1;
int pick;

void insertion ()
{
     if (rear<n-1)
     {
        rear++;
        printf ("Insert value = ");
        scanf ("%d",&array[rear]);            
     }
     else
     {
         printf ("Queues is FULL");   
     }    
}

void deletion ()
{
     if (rear!=front)
     {
        front++;
        printf ("Value to be deleted = %d", array[front]);               
     }
     else
     {
        printf ("Queues is EMPTY");   
     }   
}

void show ()
{
     if (rear!=front)
     {
        for (int i=front+1;i<=rear;i++)
        {
            printf ("%d\n",array[i]);   
        }               
     }
     else
     {
         printf ("Queues is EMPTY");   
     }    
}

void adjusted ()
{
     if (front!=rear)    
     {
        printf ("values to be deleted = %d", array[front+1]);
        for(int i=0;i<rear;i++)
        {
             array[i]=array[i+1];                  
        }
        rear--;                    
     }
     else
     {
         printf ("Queues is EMPTY");   
     }
}

int main ()
{  
    do
    {
    printf ("\n\nQueues Using Array");
    printf ("\n1. Insert Queues");
    printf ("\n2. Deletion Queues");
    printf ("\n3. Display Queues");
    printf ("\n4. Deletion Adjusted Queues");
    printf ("\nInsert your selection = ");
    scanf ("%d",&pick);
    switch (pick)
         {
         case 1:
              insertion ();
              break;
         case 2:
              deletion ();
              break;
         case 3:
              show ();
              break;
         case 4:
              adjusted ();
              break;
         }
    }while (pick!=0);  
getche ();
return 0;
}