0% found this document useful (0 votes)
24 views2 pages

Basic Queue

The document contains a C program that implements a simple queue using an array. It includes functions to enqueue (add) elements, dequeue (remove) elements, and display the current elements in the queue. The program demonstrates these functions in the main function by adding and removing elements from the queue.

Uploaded by

ahnafatif87
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Basic Queue

The document contains a C program that implements a simple queue using an array. It includes functions to enqueue (add) elements, dequeue (remove) elements, and display the current elements in the queue. The program demonstrates these functions in the main function by adding and removing elements from the queue.

Uploaded by

ahnafatif87
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <stdio.

h>
#define SIZE 5

int queue[SIZE];
int front =-1;
int rear=-1;

void enqueue(int n){


if(rear==SIZE-1){
printf("Queue is full! You can't add element");
}
else{
if(front=-1){
front = 0;
}
rear++;
queue[rear]=n;
printf("%d Value added in the queue\n ", n);

}
void dequeue(){
if(rear==-1 && front == -1){
printf("Queue is empty: ");
}
else{
printf(" Dequed value is: %d ", queue[front]);
front++;
if(front>rear){
front=rear=-1;
}
}

}
void showQueue(){
printf("Show the elements in the queue:\n");
if(rear==-1 && front==-1){
printf("Queue is empty: ");
}
else{

for(int i=front;i<=rear;i++){
printf("%d ", queue[i]);
}
}
}

int main()
{
enqueue(10);
enqueue(20);
enqueue(30);
showQueue();
dequeue();
showQueue();

return 0;
}

You might also like