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

Assignment

The document contains a C program that implements a queue using a linked list. It defines the structure for nodes and the queue, along with functions to create a queue, enqueue and dequeue elements, check the front element, and determine if the queue is empty. The main function demonstrates the usage of these queue operations.

Uploaded by

quotextrading826
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)
5 views

Assignment

The document contains a C program that implements a queue using a linked list. It defines the structure for nodes and the queue, along with functions to create a queue, enqueue and dequeue elements, check the front element, and determine if the queue is empty. The main function demonstrates the usage of these queue operations.

Uploaded by

quotextrading826
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/ 3

#include <stdio.

h>

#include <stdlib.h>

Struct Node {

Int data;

Struct Node* next;

};

Struct Queue {

Struct Node *front, *rear;

};

Struct Queue* createQueue() {

Struct Queue* q = (struct Queue*)malloc(sizeof(struct Queue));

q->front = q->rear = NULL;

return q;

Void Enqueue(struct Queue* q, int value) {

Struct Node* temp = (struct Node*)malloc(sizeof(struct Node));

Temp->data = value;

Temp->next = NULL;

If (q->rear == NULL) {

q->front = q->rear = temp;

return;

q->rear->next = temp;
q->rear = temp;

Int Dequeue(struct Queue* q) {

If (q->front == NULL) {

Printf(“Queue is empty\n”);

Return -1;

Struct Node* temp = q->front;

Int result = temp->data;

q->front = q->front->next;

if (q->front == NULL)

q->rear = NULL;

free(temp);

return result;

Int Front(struct Queue* q) {

If (q->front == NULL) {

Printf(“Queue is empty\n”);

Return -1;

Return q->front->data;

Int isEmpty(struct Queue* q) {

Return (q->front == NULL);

}
Int main() {

Struct Queue* q = createQueue();

Enqueue(q, 10);

Enqueue(q, 20);

Printf(“Front: %d\n”, Front(q));

Printf(“Dequeued: %d\n”, Dequeue(q));

Printf(“Is empty? %d\n”, isEmpty(q));

Return 0;

You might also like