0% found this document useful (0 votes)
39 views

Queue Formatted Program Widout Algorithm

This document discusses a C program that implements a queue using an array. The program allows the user to add elements to the queue, delete elements from the queue, and display all elements currently in the queue. It uses functions like empty(), full(), add(), delete(), and display() to manage the queue. The output shows example interactions where the user adds 5 elements to the queue, displays the queue contents, deletes 1 element, and again displays the updated queue.

Uploaded by

Vinay Ahlawat
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Queue Formatted Program Widout Algorithm

This document discusses a C program that implements a queue using an array. The program allows the user to add elements to the queue, delete elements from the queue, and display all elements currently in the queue. It uses functions like empty(), full(), add(), delete(), and display() to manage the queue. The output shows example interactions where the user adds 5 elements to the queue, displays the queue contents, deletes 1 element, and again displays the updated queue.

Uploaded by

Vinay Ahlawat
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Algorithm and Programming for QUEUE USING C PROGRAMMING

PROGRAM :
#include<stdio.h.> #include<conio.h> #define MAXSIZE 10 struct st { int front,rear; int queue[MAXSIZE]; }; struct st s; int empty(void); int full(void); void add(void); void delete(void); void display(void); void main() { char ans; int ch; s.front = 0; s.rear = 0; do { clrscr(); printf("********Queue Program**********\n"); printf("1. ADD\n"); printf("2. DELETE\n"); printf("3. DISPLAY\n"); printf("4. QUIT\n"); printf("Enter Your Choice : ");

scanf("%d",&ch); switch(ch) { case 1: add(); break; case 2: delete(); break; case 3: display(); break; case 4: exit(1); break; default: printf("INVALID CHOICE!!!!!!!!!!!!!!!!\n"); break; } printf("\nWant To Go To The Main Menu[y/n]"); flushall(); ans = getch(); } while(ans == 'y' ans == 'Y'); printf("\nPress Any Key To Continue\n"); getch(); } int full(void) { if (s.rear == MAXSIZE) return(1); else return(0); } int empty(void) { if (s.front == s.rear + 1) return(1); else return(0); } void add(void) { char ch; int x;

do { if(full() == 1) { printf("\n\nQueue Full\n"); break; } else { s.rear = s.rear + 1; printf("\nEnter An Element to Be Added "); scanf("%d",&x); s.queue[s.rear] = x; if(s.rear == 1) s.front ++; } printf("\nDo You Want to Add More Elements[y/n]:"); flushall(); ch = getch(); } while(ch=='y' ch == 'Y'); } void delete(void) { char ch; do { if(empty() == 1) { printf("\n\nQueue Empty\n"); break; } else { printf("% d Has Been Deleted!",s.queue[s.front]); s.front = s.front +1; } printf("\nWant to Delete More [y\n]"); flushall(); ch = getch(); } while(ch=='y' ch == 'Y'); } void display(void) { int i;

clrscr(); if(empty () == 1) printf("\nQueue Empty!!"); else { printf("\nDisplaying Queue\n"); for(i = s.front;i printf("%d\n",s.queue[i]); } }

OUTPUT: Queue Program:


1. ADD 2. DELETE 3. DISPLAY 4. QUIT Enter Your Choice : 1 Enter An Element to Be Added 1 Do You Want to Add More Elements[y/n]:y Enter An Element to Be Added 2 Do You Want to Add More Elements[y/n]:y Enter An Element to Be Added 3 Do You Want to Add More Elements[y/n]:y Enter An Element to Be Added 4 Do You Want to Add More Elements[y/n]:y Enter An Element to Be Added 5 Do You Want to Add More Elements[y/n]:n Want To Go To The Main Menu[y\n] y

Queue Program:
1. ADD 2. DELETE 3. DISPLAY 4. QUIT Enter Your Choice : 3 Displaying Queue 1 2 3 4 5 Want To Go To The Main Menu[y\n] y

Queue Program:
1. ADD 2. DELETE 3. DISPLAY 4. QUIT Enter Your Choice : 2

1 Has Been Deleted!! Do You Want To Delete More?[y/n] n Want to Go To Main Menue[y/n] y

Queue Program:
1. ADD 2. DELETE 3. DISPLAY 4. QUIT Enter Your Choice : 3 Displaying Queue 2 3 4 5 Want To Go To The Main Menu[y\n] y

Queue Program:
1. ADD 2. DELETE 3. DISPLAY 4. QUIT Enter Your Choice : 4

You might also like