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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / 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

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

Answer / vinit

#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 ?    26 Yes 36 No

Post New Answer

More C Interview Questions

Explain what are reserved words?

0 Answers  


What is volatile variable how do you declare it?

0 Answers  


What is actual argument?

0 Answers  


a simple program in c language

5 Answers   IBM,


what will be the output of this program? void main() { int a[]={5,10,15}; int i=0,num; num=a[++i] + ++i +(++i); printf("%d",num); }

6 Answers   Microsoft,






Is null equal to 0 in sql?

0 Answers  


What is difference between %d and %i in c?

0 Answers  


why arithmetic operation can’t be performed on a void pointer?

1 Answers  


in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.

0 Answers   TCS,


what does the following code do? fn(int n,int p,int r) { static int a=p; switch(n){ case 4:a+=a*r; case 3:a+=a*r; case 2:a+=a*r; case 1:a+=a*r; } } a.computes simple interest for one year b.computes amount on compound interest for 1 to 4 years c.computes simple interest for four year d.computes compound interst for 1 year

7 Answers   TCS,


Describe for loop and write a c program to sum the series X + x2/2! + x3 /3! + …….. up to fifteen terms.

2 Answers  


what's the return value of malloc()

9 Answers  


Categories