/*Dynamic Queue Programe*/
#include <stdio.h>
#include <string.h>
#include <alloc.h>
struct msg_type
{
int aircraft_no;
char name [30];
char type [30];
struct msg_type*next;
};
struct msg_type *front=NULL;
struct msg_type *rear=NULL;
void add (struct msg_type);
struct msg_type remove1();
void find (void);
void display (void);
void exit (void);
main()
{
int option=0;
struct msg_type tempmsg;
do
{
clrscr();
printf("\n\n\t\t\t(DYNAMIC QUEUE)\n");
printf("\n\t\t(MENU)\n");
printf("================================\n");
printf("1.Add Aircraft Detail\n");
printf("2.Remove Email\n");
printf("3.Find details by Aircraft number\n");
printf("4.List all Display\n");
printf("5.Exit\n");
printf("================================\n");
printf("\n");
printf("Enter your option\n");
scanf("%d", &option);
switch (option)
{
case 1: /*Add elements in the Dynamic Queue*/
printf("Enter the Aircraft number:\n");
fflush(stdin);
scanf("%d",&tempmsg.aircraft_no);
printf("Enter the name:\n");
fflush(stdin);
gets(tempmsg.name); /*scanf("%s"tempmsg.name);*/
printf("Enter the Type:\n");
gets(tempmsg.type); /*scanf ("%s",tempmsg.message);*/
tempmsg.next=NULL;
add (tempmsg);
getche();
break;
case 2:
if (front==NULL) /*Remove elements from the Dynamic Queue*/
printf ("Queue is empty\n");
else
{
tempmsg=remove1();
printf("The Removed Element is:-\n");
printf("--------------------------\n");
printf("Aircraft Number :%d\n",tempmsg.aircraft_no);
printf("Name :%s\n",tempmsg.name);
printf(" :%s\n",tempmsg.type);
printf("\n");
}
getche();
break;
case 3:
find(); /*Find the arrival number from the Dynamic Queue*/
getche();
break;
case 4:
display(); /*Display all elements in the Dynamic Queue*/
getche();
break;
case 5:
exit();
printf("Thank You, Porgrame is Over\n");
getche();
break;
default:
printf("Wrong option,Please choose from Menu\n"); /*if user chose wrong option*/
getche();
break;
}
}
while (option!=5);
}
/*Main Programe Function started here*/
void add (struct msg_type msg)
{
struct msg_type*node=NULL;
node=(struct msg_type*)malloc(sizeof(struct msg_type));
node->aircraft_no=msg.aircraft_no;
strcpy(node->name,msg.name);
strcpy(node->type,msg.type);
node->next=NULL;
if (front==NULL)
{
front=node;
rear=node;
}
else
{
rear->next=node;
rear=node;
}
}
struct msg_type remove1(void) /*Remove elements from the Dynamic Queue*/
{
struct msg_type temp;
struct msg_type *tempptr;
temp=*front;
tempptr=front;
if(tempptr==front)
front=front->next;
free((void*)front);
return temp;
}
void find (void) /*Find arrival number from the Dynamic Queue*/
{
int found=0,aircraft;
struct msg_type *ptr;
struct msg_type msg;
ptr=front;
printf("Find the Aircraft Number:\n");
scanf("%d",&aircraft);
while (ptr!=NULL)
{
msg=*ptr;
if(aircraft==msg.aircraft_no) /*compyring if the arrival is equal to arrival number in the Dynamic queue*/
{
printf("\n");
printf("The Aircraft number is available in the Dynamic Queue\n");
printf("\n\%s\t%s\t\t\t%s\n","Aircraft_No","Name","Type");
printf("\-----------------------------------------------------------");
printf("\n%d\t\t%s\t\t%s\n",msg.aircraft_no,msg.name,msg.type);
printf("\n");
found=1;
}
ptr=ptr->next;
}
if(!found)
printf ("\n Aircraft Number is not avilable\n");
}
void display (void) /*Display all elements in the Dynamic Queue*/
{
struct msg_type*ptr;
struct msg_type msg;
ptr=front;
printf("\n%s\t%s\t\t\t%s","aircraft_No","Name","Type");
printf("\n----------------------------------------------------------");
while(ptr!=NULL)
{
msg=*ptr;
printf("\n%d\t\t%s\t\t%s\n",msg.aircraft_no,msg.name,msg.type);
ptr=ptr->next;
}
}