Professional Documents
Culture Documents
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_____");
while(1)
{
printf("\n enter your choice:");
scanf("%d",&ch);
switch(ch)
case 1:
scanf("%d",&value);
insert(value)
; break;
case
2:delete();
break;
case 3:display();
break;
case 4:exit(0);
default:printf("invalid choice");
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;
void delete()
if(front==NULL)
else
struct Node*temp=front;
front=front->next;
free(temp);
}
void display()
if(front==NULL)
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_____");
while(1)
scanf("%d",&ch);
switch(ch)
case 1:
scanf(" %c",&value);
insert(value)
; break;
case
2:delete();
break;
case 3:display();
break;
case 4:exit(0);
default:printf("invalid choice");
}
}
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;
void delete()
if(front==NULL)
els
e
{
struct Node*temp=front;
front=front->next;
printf("\n deleted element %c",temp->data);
free(temp);
void display()
if(front==NULL)
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)
scanf("%d",&ch);
switch(ch)
case 1:
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)
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)
else{
while(i!=rear)
{ printf("%d",Queue[i]);
i=(i+1)%N;
printf("%d",Queue[rear]);
OUTPUT
:
ence= :he da:a :o
inser::10