c program to add and delete an element from circular queue
using array
Answer Posted / smriti
program to add and delete an element from circular queue
using array
Answer
# 2 #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 ? | 1 Yes | 3 No |
Post New Answer View All Answers
Is the exit() function same as the return statement? Explain.
What is structure and union in c?
What is %s and %d in c?
How can I handle floating-point exceptions gracefully?
Calculate 1*2*3*____*n using recursive function??
Explain how can a program be made to print the line number where an error occurs?
What is a floating point in c?
What are the types of i/o functions?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.
What is keyword with example?
Can the “if” function be used in comparing strings?
What is the use of bit field?
Why isn't any of this standardized in c? Any real program has to do some of these things.
How can a program be made to print the name of a source file where an error occurs?