Wednesday, June 1, 2016

WAP to implement Queue of strings

#include<stdio.h>
#include<conio.h>
#include<string.h>
int r=-1,f=-1;
char sq[5][50];
void insert(char s[])
{
if(r==4)
{
printf("Queue is full");
return;
}
r++;
strcpy(sq[r],s);
if(f==-1)
f=0;
}
char* del()
{
char *x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
strcpy(x,sq[f]);
if(f==r)
{
f=-1;
r=-1;
}
else
{
f++;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("Queue is empty");
return;
}
printf("\n Values in queue are:");
for(i=f;i<=r;i++)
{
printf("| %s | ",sq[i]);
}
}
void main()
{
int n,x;
char s[50];
clrscr();
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter string :");
scanf("%s",s);
insert(s);
break;
case 2:
//*st=del();
printf("\n Deleted value is %s",del());
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=4);
getch();
}

No comments:

Post a Comment