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

C Enqueue and Display

The document defines a queue data structure with functions to enqueue and display elements. It initializes a queue with capacity 4, enqueues elements until full, and displays the queue contents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

C Enqueue and Display

The document defines a queue data structure with functions to enqueue and display elements. It initializes a queue with capacity 4, enqueues elements until full, and displays the queue contents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <bits/stdc++.

h>
using namespace std;

struct Queue {
int front, rear, capacity;
int* queue;
Queue(int c)
{
front = rear = 0;
capacity = c;
queue = new int;
}

void queueEnqueue(int data)


{
if (capacity == rear) {
printf("\nQueue is full\n");
return;
}

else {
queue[rear] = data;
rear++;
}
return;
}

void queueDisplay()
{
int i;
if (front == rear) {
printf("\nQueue is Empty\n");
return;
}
for (i = front; i < rear; i++) {
printf(" %d <-- ", queue[i]);
}
return;
}
int main(void)
{
Queue q(4);
q.queueDisplay();
q.queueEnqueue(20);
q.queueEnqueue(30);
q.queueEnqueue(40);
q.queueEnqueue(50);
q.queueDisplay();
q.queueEnqueue(60);

return 0;
}

output:
Queue is Empty
20 <-- 30 <-- 40 <-- 50 <--
Queue is full
20 <-- 30 <-- 40 <-- 50 <--

You might also like