• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Queue Operations using C Language

April 5, 2011 by ProjectsGeek Leave a Comment

Queue Operations using C Language

 

Write a program to Queue Operations using C Language to implement the following functions :

  • Create Queue
  • Delete Queue
  • Display Queue
  • Delete Queue

Queue Operations using C Language Code

#include  
 #include  
 #include  
 typedef struct queue  
 {  
 char name[20];  
 char diesease[50];  
 struct add  
 {  
 int hno;  
 int sno;  
 char city[20];  
 }add;  
 struct queue * link;  
 }queue;  
 typedef struct prior  
 {  
 queue * front;  
 queue * rear;  
 int priority;  
 struct prior * next;  
 }prior;  
 prior *create();  
 prior *delet(prior *);  
 void display(queue *,int *);  
 void alloc(queue *);  
 prior *freeall(prior *);  
 void main()  
 {  
 int ch,ch1,temp;  
 prior *t,*f=NULL;  
 do  
 {  
 clrscr();  
 printf("\n\t1.CREATE\n\t2.DELETE\n\t3.DISPLAY\n\t4.EXIT\n\tENTER UR CHOICE:");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1: if(f!=NULL)  
 f=freeall(f);  
 printf("\nCREATE");  
 f=create();  
 break;  
 case 2:  
 if(f==NULL)  
 printf("FIRST CREATE !!!!!");  
 else  
 {  
 printf("\nDELETE");  
 f=delet(f);  
 }  
 getch();  
 break;  
 case 3:  
 if(f==NULL)  
 printf("FIRST CREATE !!!!!");  
 else  
 {  
 do  
 {  
 clrscr();  
 printf("\n\tDISPLAY\n\t1.BY CATEGORY\n\t2.ALL\n\t3.EXIT\n\tENTER UR CHOICE");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 printf("\nENTER THE CATEGORY:\n1.SERIOUS\n2.NON-SERIOUS\n3.GENERAL");  
 scanf("%d",&ch);  
 temp=1;  
 t=f;  
 clrscr();  
 while(t!=NULL)  
 {  
 if(t->priority==ch)  
 break;  
 t=t->next;  
 }  
 if(t!=NULL)  
 display(t->front,&temp);  
 else  
 printf("NOT FOUND");  
 getch();  
 break;  
 case 2:  
 t=f;  
 temp=1;  
 clrscr();  
 while(t!=NULL)  
 {  
 display(t->front,&temp);  
 t=t->next;  
 }  
 getch();  
 break;  
 case 3:  
 break;  
 default:printf("\nINVALID CHOICE");  
 }  
 }while(ch1!=3);  
 }  
 getch();  
 break;  
 case 4:  
 break;  
 default:printf("\nINVALID CHOICE");  
 }  
 }while(ch!=4);  
 getch();  
 }  
 prior * create()  
 {  
 int p;  
 prior *f=NULL,*nw1,*t;  
 queue *nw;  
 do  
 {  
 nw=(queue *)malloc(sizeof(queue));  
 nw->link=NULL;  
 alloc(nw);  
 printf("\nGIVE THE PRIORITY TO THIS PATIENT:");  
 while(1)  
 {  
 scanf("%d",&p);  
 if(p>0&&p<4)  
 break;  
 else  
 printf("INVALID PRIORITY");  
 }  
 if(f==NULL)  
 {  
 nw1=(prior *)malloc(sizeof(prior));  
 nw1->next=NULL;  
 nw1->priority=p;  
 nw1->front=nw;  
 nw1->rear=nw;  
 f=nw1;  
 }  
 else  
 {  
 if(f->priority>p)  
 {  
 nw1=(prior *)malloc(sizeof(prior));  
 nw1->next=NULL;  
 nw1->priority=p;  
 nw1->front=nw;  
 nw1->rear=nw;  
 nw1->next=f;  
 f=nw1;  
 }  
 t=f;  
 while(p>=t->next->priority&&t->next!=NULL)  
 t=t->next;  
 if(p==t->priority)  
 {  
 t->rear->link=nw;  
 t->rear=nw;  
 }  
 else  
 {  
 nw1=(prior *)malloc(sizeof(prior));  
 nw1->next=NULL;  
 nw1->priority=p;  
 nw1->front=nw;  
 nw1->rear=nw;  
 nw1->next=t->next;  
 t->next=nw1;  
 }  
 }  
 printf("DO U WANT TO ENTER MORE:");  
 }while(getche()=='y'||getche()=='Y');  
 return f;  
 }  
 void alloc(queue *nw)  
 {  
 printf("\nENTER NAME:");  
 flushall();  
 gets(nw->name);  
 printf("\nENTER DIESEASE:");  
 flushall();  
 gets(nw->diesease);  
 printf("\nENTER H.NO:");  
 scanf("%d",&(nw->add.hno));  
 printf("\nENTER S.NO:");  
 scanf("%d",&(nw->add.sno));  
 printf("\nENTER CITY:");  
 flushall();  
 gets(nw->add.city);  
 }  
 void display(queue *t,int *temp)  
 {  
 while(t!=NULL)  
 {  
 printf("\n\nNAME:");  
 printf("%s",t->name);  
 printf("\nDIESEASE:");  
 printf("%s",t->diesease);  
 printf("\nADDRESS");  
 printf("\nHOUSE.NO:");  
 printf("%d",(t->add.hno));  
 printf("\nSTREET.NO:");  
 printf("%d",(t->add.sno));  
 printf("\nCITY:");  
 printf("%s",(t->add.city));  
 t=t->link;  
 getch();  
 }  
 }  
 prior *delet(prior *f)  
 {  
 prior *nw;  
 queue *q,*q1;  
 q=f->front;  
 if(q->link==NULL)  
 {  
 nw=f;  
 f=f->next;  
 free(nw);  
 }  
 else  
 f->front=q->link;  
 free(q);  
 printf("\nDATA is DELETED!!!!!!");  
 getch();  
 return f;  
 }  
 prior *freeall(prior *f)  
 {  
 prior *t;  
 queue *s,*r;  
 while(f!=NULL)  
 {  
 r=f->front;  
 while(r!=NULL)  
 {  
 s=r;  
 r=r->link;  
 free(s);  
 }  
 t=f;  
 f=f->next;  
 free(t);  
 }  
 return f;  
 }

 

Other Projects to Try:

  1. Breadth First and Depth First Search C Language
  2. Hoffmans algorithm in C Language
  3. BFS AND DFS Algorithm using C Language
  4. Stack Operations using C Language
  5. Primitive operations on Sequential file in C language

Filed Under: C Assignments, Datastructure and Files Tagged With: Datastructure Assignments

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy