0% found this document useful (0 votes)
16 views4 pages

Aiml14 DS Exp8

The document describes a C program to implement a queue using a linked list. It defines a node structure with data and pointer fields. Functions are created to enqueue nodes to the rear, dequeue nodes from the front, and print the queue. The main function takes user input to insert nodes, prints the initial queue, then repeatedly dequeues and prints the updated queue. The conclusion states the experiment demonstrated creating a queue with a linked list.

Uploaded by

Purva Jage
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)
16 views4 pages

Aiml14 DS Exp8

The document describes a C program to implement a queue using a linked list. It defines a node structure with data and pointer fields. Functions are created to enqueue nodes to the rear, dequeue nodes from the front, and print the queue. The main function takes user input to insert nodes, prints the initial queue, then repeatedly dequeues and prints the updated queue. The conclusion states the experiment demonstrated creating a queue with a linked list.

Uploaded by

Purva Jage
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/ 4

DATA STRUCTURE

EXPERIMENT : 8
NAME : JAGE TANVI NARENDRA
ROLL NO. : AIML14
BATCH : A1
BRANCH : CSE(AIML)
AIM :
Write a program to implement a queue using a linked list.

SOURCE CODE :
#include<stdio.h>
#include<stdlib.h>

struct node
{
int data;
struct node *next;
};
struct node *front = NULL, *rear = NULL;
void enqueue(int val)
{
struct node *newnode = malloc(sizeof(struct node));
newnode -> data = val;
newnode ->next = NULL;
if (front == NULL && rear == NULL)
front = rear = newnode;
else{
rear ->next = newnode;
rear = newnode;
}
}
void dequeue()
{
struct node*temp;
if(front == NULL)
printf("queue is empty. unable to perfor dequeue\n");
else{
temp = front;
front = front ->next;
free(temp);
}
}
void printlist()
{
struct node *temp =front;
while(temp)
{
printf("%d->",temp->data);
temp=temp->next;
}
printf("NULL\n");

int main()
{
int m,n,i;
printf("type how many data to be inserted");
scanf("%d",&n);
for(i = 0; i<n; i = i+1)
{
printf("type the data to be inserte");
scanf("%d",&m);
enqueue(m);
}
printf("Queue :");
printlist();
for (i=n;i>0; i--){
dequeue(m);
printf("after dequeue the then new list :");
printlist();
}
return 0;

OUTPUT :

CONCLUSION :
From this experiment we have learnt to create a queue using a linked list.

You might also like