Wisdom Materials
Home
About Us
Our Clients
Careers
Services
Education
Jobs
News
Business
Health
Astrology
Entertainment
RealEstate
Devotion
Contact Us
Data Structures using C Language
/ Queue Implementation using C program
Program
Copy text
#include
#define MAX 50 void insert();void delete();void display(); int queue_array[50]; int rear = - 1; int front = - 1; main() { int choice; while (1){ printf("Enter your choice : \n\t 1.Insert \t 2.Delete \t 3. Display elements \t 4.Quit \n"); scanf("%d", &choice); switch (choice) { case 1:insert();break; case 2:delete();break; case 3:display();break; case 4:exit(1);default: printf("Enter correct choice \n"); } } } void insert(){ int add_item; if (rear == MAX - 1) printf("Queue Overflow \n"); else { if (front == - 1) /*If queue is initially empty */ front = 0; printf("Insert the element in queue : "); scanf("%d", &add_item); rear = rear + 1; queue_array[rear] = add_item; } } void delete(){ if (front == - 1 || front > rear) { printf("Queue Underflow \n"); return ; } else { printf("Element deleted from queue is : %d\n", queue_array[front]); front = front + 1; } } void display(){ int i; if (front == - 1) printf("Queue is empty \n"); else { printf("Queue is : \n"); for (i = front; i <= rear; i++) printf("%d ", queue_array[i]); printf("\n"); } }
Output
Home
Back