Queue Implementation Using Array C Program
queue_array.txt
File size: 1.17 KB
File content type: text/plain
Category: Practical Files
Subject: Data Structure
#include<stdio.h>
#define MAXSIZE 5
void enqueue();
int dequeue();
void peek();
int isEmpty();
int isFull();
int queue[MAXSIZE];
int rear = -1, front = -1;
void main() {
int value, choice;
while(1) {
printf("Enter choice.\n1. Push\n2. Pop\n3. Display\n4. Exit\n");
scanf("%d",&choice);
switch(choice) {
case 1: if(isFull()) {
printf("Cannot push. Overflow.\n");
break;
}
printf("Enter number\n");
scanf("%d",&value);
enqueue(value);
break;
case 2: if(isEmpty()) {
printf("Cannot pop. Underflow.\n");
break;
}
value = dequeue();
printf("Value popped = %d\n",value);
break;
case 3: peek();
break;
case 4: return;
}
}
}
int isFull() {
if(rear == MAXSIZE-1)
return 1;
return 0;
}
int isEmpty() {
if(front == -1 || front > rear)
return 1;
return 0;
}
void enqueue(int value) {
queue[++rear] = value;
if(front == -1)
front++;
}
int dequeue() {
int value = queue[front++];
return value;
}
void peek() {
int i;
for(i=front;i<=rear;i++)
printf("%d ",queue[i]);
printf("\n");
}
Queue using array in C
Last Updated: July 16, 2022
Related
Data Mining Practical File Exp-8-11
Category: Practical FilesJuly 16, 2022
IPU CA Notes Unit 3
Category: NotesJuly 16, 2022
Ordinary Differential Equations
Category: NotesJuly 16, 2022
Tower of Hanoi Iterative C
Category: Practical FilesJuly 17, 2022
Advance Control System Unit 3 Non Linear
Category: NotesJuly 17, 2022
Special Theory of Relativity Notes
Category: NotesJuly 16, 2022
IPU IBM Notes Unit 3
Category: NotesJuly 17, 2022
Java Program to check if a number is prime
Category: Practical FilesJuly 16, 2022
IPU Information Systems Management Notes Unit 4
Category: NotesJuly 17, 2022
Two Way Switch Bulb (Filament)
Category: Practical FilesJuly 16, 2022