You are on page 1of 5

Chintan Undhad

91900133035
DSA

#include<stdio.h>

#include<malloc.h>

//Global Declaration Section

//Structure called Node

struct Node

int value;

struct Node *next;

}*front=NULL,*rear=NULL;

int queueSize;

int currSize=-1;

//Function Declaration

void enqueue(int);

void dequeue();

void printQueue();

void queueOperations();

int main()

int choice,data;

printf("\n Enter Your Queue Size :");

scanf("%d",&queueSize);
do

queueOperations();

printf("\n Select Functions :");

scanf("%d",&choice);

switch(choice)

case 1:

printf("\n Enter Value : ");

scanf("%d",&data);

enqueue(data);

break;

case 2:

dequeue();

break;

case 3:

printQueue();

break;

}while(choice!=4);

return 0;

void queueOperations()

printf("\n ==========================");

printf("\n Queue Operations");

printf("\n ==========================");

printf("\n 1 - Enqueue");

printf("\n 2 - Dequeue");
printf("\n 3 - Print");

printf("\n 4 - Exit");

printf("\n ==========================");

void enqueue(int n)

struct Node *temp=NULL;

if(currSize==queueSize-1)

printf("\n Queue is Full");

else

currSize++;

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

temp->next=NULL;

temp->value=n;

if(front == NULL && rear==NULL)

front=temp;

rear=temp;

else

rear->next=temp;

rear=temp; // rear = rear->next

}
}

void dequeue()

struct Node *temp=NULL;

if(currSize==-1)

printf("\n Queue is Empty");

else

currSize --;

temp = front;

front = front->next;

printf("\n %d is dequeue ",temp->value);

free(temp);

if(front == NULL)

rear = NULL;

void printQueue()

struct Node *head=NULL;

if(currSize==-1)

printf("\n Queue is Empty");

else

{
head=front;

while(head!=NULL)

printf("%d -> ",head->value);

head=head->next;

You might also like