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

Program of Queue Using Array

This C program implements a queue using an array. It defines functions to insert elements into the queue, delete elements from the queue, and display the contents of the queue. The main function contains a menu loop that calls these functions based on the user's selection and allows them to interactively manage the queue.

Uploaded by

Rizwan Hameed
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)
10 views

Program of Queue Using Array

This C program implements a queue using an array. It defines functions to insert elements into the queue, delete elements from the queue, and display the contents of the queue. The main function contains a menu loop that calls these functions based on the user's selection and allows them to interactively manage the queue.

Uploaded by

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

/*Program of queue using array*/

# include # define MAX 5 int queue_arr[MAX]; int rear = -1; int front = -1; main() { int choice; while(1) { printf("1.Insert\n"); printf("2.Delete\n"); printf("3.Display\n"); printf("4.Quit\n"); printf("Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1 : insert(); break; case 2 : del(); break; case 3: display(); break; case 4: exit(1); default: printf("Wrong choice\n"); }/*End of switch*/ }/*End of while*/ }/*End of main()*/ insert() { int added_item; if (rear==MAX-1) printf("Queue Overflow\n"); else { if (front==-1) /*If queue is initially empty */ front=0; printf("Input the element for adding in queue : "); scanf("%d", &added_item); rear=rear+1; queue_arr[rear] = added_item ; } }/*End of insert()*/ del() {

if (front == -1 || front > rear) { printf("Queue Underflow\n"); return ; } else { printf("Element deleted from queue is : %d\n", queue_arr[front]); front=front+1; } }/*End of del() */ 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_arr[i]); printf("\n"); } }/*End of display() */

You might also like