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

write a program to rearrange the array such way that all even elements should come first and next come odd

1766


What are the keywords in c?

646


how could explain about job profile

1459


What is size of union in c?

584


Explain the difference between strcpy() and memcpy() function?

599






What are the various types of control structures in programming?

631


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3129


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

3506


What is bss in c?

609


Explain what are reserved words?

638


If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402

3251


Can we declare function inside main?

572


"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks

662


FILE PROGRAMMING

1781


Explain threaded binary trees?

684