c program to add and delete an element from circular queue
using array

Answer Posted / pooja patial

#include<stdio.H>
#include<conio.h>
#define MAXQ 10
struct cq
{
int data[MAX];
int front,rear;
};
void add(struct cq*,int);
int del(struct cq*);
void main()
{
int ch,item;
struct cq q1;
q1.front=q1.rear=-1;
printf("\t\tMAIN MENU\n");
printf("\t\t************\n");
printf("\t\t 1.Add in a circular queue\n");
printf("\t\t 2.delete from circular queue\n");
printf("\t\t 3.Exit\n");
printf("\t\t Enter your choice\n");
scanf("%d",&ch);
clrscr();
switch(ch)
{
case 1:
printf("Enter the value which is to be add:-");
scanf("%d",&item);
add(&q1,item);
break;
case 2:
item=del(&q1);
if(item!=NULL)
printf("Delete value ->%d",item);
break;
case 3:
break;
default:
printf("Wromg choice !Try again") ;
}
getch();
}
while(ch!=3);
}

void add(struct cq*p,int item)
{
if(p->rear==MAX-1 && p->front==0 || p->rear+1==p->front)
{
printf("Queue is full\n");
return;
}
if(p-.front==-1)
p->front=p->raer=0;
else if(p->rear=MAX-1)
p->rear=0;
else
p->rear++;
p->data[p->rear]=item;
}

int del(struct cq*p)
{
int item;
if(p->front==-1)
{
printf("Queue is Empty");
return(NULL);
}
item=p->data[p->front];
if(p->front==p->rear)
p->front=p->rear=-1;
else if(p->front==MAX-1)
p->front=0;
else
p->front++;
return(item);
}

Is This Answer Correct ?    12 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is c variable?

544


how many errors in c explain deply

1623


What are the data types present in c?

617


Are there constructors in c?

586


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

705






What is #pragma statements?

583


write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.

3329


How can a process change an environment variable in its caller?

645


What are the three constants used in c?

538


What is the difference between void main and main in c?

613


Compare interpreters and compilers.

633


What is the scope of an external variable in c?

561


Write a code of a general series where the next element is the sum of last k terms.

582


How to write a multi-statement macro?

616


i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me

1475