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

what is constant pointer?

3 Answers  


a linear linked list such that the link field of its last node points to the first node instead of containing NULL a) linked list b) circular linked list c) sequential linked list d) none

0 Answers  


write a programe to find the factorial of given number using recursion

3 Answers  


What is the meaning of ?

0 Answers  


how to get starting address of a running C program

3 Answers  






What is a #include preprocessor?

0 Answers  


what are # pragma staments?

0 Answers  


How do you list files in a directory?

0 Answers  


what is the difference between normal variables and pointer variables..............

15 Answers   HP, Infosys, Satyam, Vivekanand Education Society,


write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.

0 Answers   HCL,


What are the different types of pointers used in c language?

0 Answers  


What is malloc() function?

0 Answers  


Categories