New Member FAQ | Forums | Earn Revenue | Posting Guidelines | Help Topics


ResourcesPractice TestsAsk ExpertsQuestion PapersJobsStudy in UKUniversitiesCollegesCoursesSchoolsTraining


My Profile

Awards & Gifts


Active Members
TodayLast 7 Daysmore...





Implementation of Circular Queue using Array


Posted Date:     Total Responses: 0    Posted By: pankaj agarwala   Member Level: Silver   Points/Cash: 3   


#### Write a C program to insert,delete and show an element in QUEUE.




#define MAX 10
#include
#include
int queue[MAX];
int f=-1,r=-1;
void insertrear(int no)
{
if((f==0&&r==MAX-1)||(r+1==f))
{
printf("Queue is full");
return;
}
else
{
if(r==-1)
f=r=0;
else if(r==MAX-1)
r=0;
else
r++;
queue[r]=no;
}
}





int deletefront()
{
int val;
if(f==-1)
{
printf("Empty Queue");
return -999;
}
else
{
val=queue[f];
if(f==r)
f=r=-1;
else if (f==MAX -1)
f=0;
else
f++;
}
return val;
}






void show()
{
int i;
if(f==r)
printf(" %d ",queue[f]);
else if(f>r)
{
for(i=f;i {
printf(" %d ",queue[i]);
}
for(i=0;i<=r;i++)
printf(" %d",queue[i]);
}
else if(r>f)
{
for(i=f;i<=r;i++)
{
printf(" %d",queue[i]);
}
}
}






void main()
{
clrscr();
int val , ch;
do
{
printf("\n 1 Insert rear");
printf("\n 2 delete front");

printf("\n 3 show");
printf("\n 0 EXIT");
printf("\n enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\n Enter number");
scanf("%d",&val);
insertrear(val);
break;
case 2: val=deletefront();
if(val!=-999)
printf("\n %d deleted",val);
break;
case 3: show();
break;
case 0:break;
default:printf("\n invalid choice");
}
}
while(ch!=0);
getch();
}



Project Feedbacks


No feedbacks found. Be the first to respond...

Post Feedback
You must Sign In to post a feedback.
Next Project: Newton Raphson's Method C language program - To find Square Root
Previous Project: Java Threading or multithreading Programs

Return to Project Index

Post New Project


Related Projects

Subscribe to Email
  • Get Jobs by Email
  • Forum posts by Email
  • Articles by Email



  • website counter

    Online Membersbenson gomez
    Ashish Kumar
    Iti Tyagi
    Sakshi Sood
    Munish kumar
    dks
    Arvind
    siva
    sathishkumar
    Ramakrishna Kambhampati
    Shiyas
    More...



    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    AdSense Revenue Sharing sites   Advertise   Talk to Tony John
    ISC Technologies, Kochi - India
    2006 - 2012 All Rights Reserved.