sir,
i cannot find the way how to write aprogram by using
array on queue
Answer Posted / ruchi
#include<stdio.h>
#include<conio.h>
void insert();
void del();
void trav();
int f=-1,r=-1,a[20],n=5;
int main()
{
int ch;
char ch1='y';
clrscr();
while(ch1=='y')
{
printf("\nMEnu ");
printf("\n1.Insertion ");
printf("\n2.Deletion ");
printf("\n3.Traversal ");
printf("\n4.Exit ");
printf("\nEnter your chioce ");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
trav();
break;
case 4:
exit(0);
}
printf("\nDo you want to repeat ");
ch1=getche();
}
}
void insert()
{
int item;
if(r<n-1)
{
printf("\nEnter the element ");
scanf("%d",&item);
if(f==-1)
{
f=0;
r=0;
}
else
r=r+1;
a[r]=item;
}
}
void del()
{
if((f>=0)&&(f<=r))
{
f=f+1;
printf("\nItem is deleted ");
}
else
{
printf("\nUnderflow ");
}
}
void trav()
{
int i;
if((f==-1)||(f>r))
{
printf("\nQueue is empty ");
}
for(i=f;i<=r;i++)
{
printf("%d\n",a[i]);
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Can we access array using pointer in c language?
What is a void pointer? When is a void pointer used?
Explain pointers in c programming?
what will be maximum number of comparisons when number of elements are given?
What kind of structure is a house?
Which are low level languages?
What is structure in c definition?
What is the size of structure in c?
A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler
Where does the name "C" come from, anyway?
What is c language and why we use it?
#include main() { char s[] = "Bouquets and Brickbats"; printf(" %c, ",*(&s[2])); printf("%s, ",s+5); printf(" %s",s); printf(" %c",*(s+2)); }
What is the explanation for cyclic nature of data types in c?
What is the difference between malloc calloc and realloc in c?
What are directives in c?