0% found this document useful (0 votes)
29 views8 pages

Data Structure Cat-1

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)
29 views8 pages

Data Structure Cat-1

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/ 8

DATA STRUCTURE AND ANALYS:

CAT-1

Name: Devendhiran.D

Reg no: 21MID0218

a. Enqueue first 5 letters of your full name as in your passport. Display location
of front and back pointers, and elements of queue.
b. Dequeue 4 times. Display location of front and back pointers, and elements of
queue.
c. Enqueue first 3 letters of your hometown. Display location of front and back
pointers, and elements of queue.
d. Dequeue 3 times. Display location of front and back pointers, and elements of
queue.

Ans:
#include<stdio.h>
int isfull(int rear,int front,int n)
{
if ((front==rear+1) || (front==0 && rear==n-1)) return 1;
return 0;
}
int isempty(int rear,int front,int n)
{
if (front==-1) return 1;
return 0;
}
void insert(int *queue,int n,int *rear,int *front,char ele)
{
if (isfull(*rear,*front,n))
{
printf("\nQueue is full\n");
}
else {
if (*front==-1)
*front = 0;
*rear = (*rear + 1) % n;
queue[*rear] = ele;
printf("\nThe letter %c is Inserted", ele);
}
}
char delet(int *queue,int n,int *rear,int *front)
{
int ele;
if(isempty(*rear,*front,n))
{
printf("\nQueue is empty\n");
return (-1);
}

else
{
ele=queue[*front];
if(*front==*rear) {
*front=-1;
*rear=-1;
}
else {
*front=(*front+1) % n;
}
printf("\nThe deleted letter= %c \n",ele);
return (ele);
}

}
char display(int *queue,int *rear,int *front,int n) {
int i;
if (isempty(*rear,*front,n))
printf(" \nThe Queue is empty\n");
else {
printf("\n Front= %d ", *front);
printf("\n letter= ");
for (i = *front; i != *rear; i = (i + 1) % n) {
printf("%c ", queue[i]);
}
printf("%c ", queue[i]);
printf("\n Rear= %d \n", *rear);
}
}

int main()
{
int n;
printf("Enter the number of queue size=");
scanf("%d",&n);
int rear=-1,front=-1;
int queue[n];
insert(queue,n,&rear,&front,'d');
insert(queue,n,&rear,&front,'e');
insert(queue,n,&rear,&front,'v');
insert(queue,n,&rear,&front,'a');
insert(queue,n,&rear,&front,'n');
display(queue,&rear,&front,n);
delet(queue,n,&rear,&front);
delet(queue,n,&rear,&front);
delet(queue,n,&rear,&front);
delet(queue,n,&rear,&front);
display(queue,&rear,&front,n);

return 0;
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy