F Dequeue Implement Using Array In C Programming | CodeTheta

Dequeue Implement Using Array In C Programming

May 13, 2014

This is a Dequeue implementation using Array. Program code is easy written not very complex you can implement it in your own and see how it will work.

If you want to know about Queue related program then click Here


/* http://native-code.blogspot.com */

#include<stdio.h>
#include<conio.h>
#define MAX 20
#define MID 10
void insertr(int a[],int x);
void insertl(int a[],int x);
int deletel(int a[]);
int deleter(int a[]);
int left,right;

void main()
{
    int a[MAX],op,x;
    left=MID;
    right=MID-1;
    for( ; ; )
    {
 printf("/* http://native-code.blogspot.com */\n");
 printf("\n\nEnter the option to start operation");
 printf("\n1.To insert leftside: ");
 printf("\n2.To insert rightside: ");
 printf("\n3.To delete from leftside: ");
 printf("\n4.To delete from rightside: ");
 printf("\n5.Exit");
 printf("\nEnter the option: ");
 scanf("%d",&op);
 switch(op)
 {
case 1:
printf("\nEnter element to insert leftside: ");
scanf("%d",&x);
insertl(a,x);
continue;
case 2:
printf("\nEnter element to insert rightside: ");
scanf("%d",&x);
insertr(a,x);
continue;
case 3:
x=deletel(a);
if(x!=-999)
printf("\nDeleted item: %d",x);
continue;
case 4:
x=deleter(a);
if(x!=-999)
printf("\nDeleted item : %d",x);
continue;
case 5:
break;
 }
    }
}

void insertr(int a[],int x)
{
++right;
if(right==MAX)
{

printf("\nQueue overflow / full");
return;
}
else
a[right]=x;
}

void insertl(int a[],int x)
{
--left;
if(left==-1)
{
 printf("\nQueue overflow / full");
 return;
}
else
a[left]=x;
}

int deletel(int a[])
{
int i;
if(left>right)
{
printf("\nQueue is empty now");
return -999;
}
else
{
 i=a[left];
 ++left;
 return i;
}
}

int deleter(int a[])
{
 int i;
 if(left>right)
 {
 printf("\nQueue is empty now");
 return -999;
 }
 else
 {
 i=a[right];
 right--;
 return i;
 }
}


/* http://native-code.blogspot.com */

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us

Post a Comment

PRODUCTS

LISTS OF PRODUCTS

SERVICES

SKILLS
SOFTWARE DEVELOPMENT
WEBSITE DEVELOPMENT
WEB HOSTING
BULK SMS SERVICE
SEO SERVICE
ANDROID APPS
QR CODE / BARCODE
HARDWARE SERVICE
OUR WORK AREA