You are on page 1of 13

WEEK-8

Name:B.Sandeep

R.NO:20R21A04J7

Date:04-01-22

problemstatement:

Write a C Program to create Linear Queue of integers using Linked List and perform
the below operations on it:

a) enqueue b) dequeue c)

display program:

#include<stdio.h>

#include<conio.h>

struct Node

int data;

struct Node*next;

}*front=NULL,*rear=NULL;

void insert(int);

void delete();

void display();

void main()

int ch,value;

printf("_ _ _ _ _Menu_____");

printf("\n 1-insert\n 2-delete\n 3-display\n 4-exit");

while(1)

{
printf("\n enter your choice:");

scanf("%d",&ch);

switch(ch)

case 1:

printf("\n enter the value to insert:");

scanf("%d",&value);

insert(value)

; break;

case

2:delete();

break;

case 3:display();

break;

case 4:exit(0);

default:printf("invalid choice");

void insert(int value)

struct Node*newNode;

newNode=(struct Node*)malloc(sizeof(struct

Node)); newNode->data=value;

newNode->next=NULL;

if(rear==NULL)
{

front=rear=newNode;
}

els
e

{
rear->next=newNode;

rear=newNode;

printf("\n insertion is successfull");

void delete()

if(front==NULL)

printf("\n queue is empty");

else

struct Node*temp=front;

front=front->next;

printf("\n deleted element %d",temp->data);

free(temp);

}
void display()

if(front==NULL)

printf("\n queue is empty");

els
e

{
struct Node*temp=front;

while(temp->next!=NULL)

printf("%d->",temp-

>data); temp=temp-

>next;

printf("%d-->NULL \n",temp->data);

OUTPUT:
problem statement:

Write a C Program to create Linear Queue of characters using Arrays and perform the
below operations on it:

a) enqueue b) dequeue c)

display program:

#include<stdio.h>

#include<conio.h>

struct Node{

int data;

struct Node*next;
}*front=NULL,*rear=NULL;

void insert(char);

void delete();

void display();

void main()

int ch,value;

printf("_ _ _ _ _Menu_____");

printf("\n 1-insert\n 2-delete\n 3-display\n 4-exit");

while(1)

printf("\n enter your choice:");

scanf("%d",&ch);

switch(ch)

case 1:

printf("\n enter the value to insert:");

scanf(" %c",&value);

insert(value)

; break;

case

2:delete();

break;

case 3:display();

break;

case 4:exit(0);

default:printf("invalid choice");

}
}

void insert(char value)

struct Node*newNode;

newNode=(struct Node*)malloc(sizeof(struct

Node)); newNode->data=value;

newNode->next=NULL;

if(rear==NULL)

front=rear=newNode;

els
e

{
rear->next=newNode;

rear=newNode;

printf("\n insertion is successfull");

void delete()

if(front==NULL)

printf("\n queue is empty");

els
e

{
struct Node*temp=front;

front=front->next;
printf("\n deleted element %c",temp->data);

free(temp);

void display()

if(front==NULL)

printf("\n queue is empty");

els
e

{
struct Node*temp=front;

while(temp->next!=NULL)

printf("%c->",temp-

>data); temp=temp-

>next;

printf("%c-->NULL \n",temp->data);

OUTPUT:
problem statement:

Write a C Program to create Linear Queue of characters using Arrays and perform the
below operations on it:

a) enqueue b) dequeue c)

display program:

#include<stdio.h>

#include<stdlib.h>

#define N 5

int Queue[N];

int front=-1;

int rear=-1;

void enqueue(int);

void deque();
void display();

void main()

int x,ch;

while(1)

printf("\n 1-enqueue\n 2-deque\n 3-display\n 4-exit");

printf("\n enter your choice:");

scanf("%d",&ch);

switch(ch)

case 1:

printf("\n enter the data to insert:");

scanf("%d",&x);

enqueue(x)

; break;

case

2:deque();

break;

case 3:display();

break;

case 4:exit(0);

void enqueue(int x)

if(front==-1&&rear==-1){

front=rear=0;

Queue[rear]=x;
}

else if((rear+1)%N==front)

printf("Queue is full");

else{ rear=(rear+

1)%N;

Queue[rear]=x;

void deque()

if(front==-1&&rear==-1)

printf("\n queue is empty");

else if(front==rear)

{ printf("%d",Queue[front

]); front=rear=-1;

else{ printf("%d",Queue[f

ront]);

front=(front+1)%N;

void display()

int i;
i=front;

if(front==-1&&rear==-1)

printf("\n queue is empty");

else{

printf("\nqueue contents are");

while(i!=rear)

{ printf("%d",Queue[i]);

i=(i+1)%N;

printf("%d",Queue[rear]);

OUTPUT

:
ence= :he da:a :o
inser::10

en:e•’ she da:a :o


inser::2O

You might also like