0% found this document useful (0 votes)
50 views2 pages

Queue Using Linked List

This C program implements a queue using a linked list data structure. It defines Node and front/rear pointers to track the queue. The enqueue function adds a new node to the rear, dequeue removes the front node and returns its data, and Display prints the queue. The main function tests it by enqueueing several values, displaying the queue, dequeueing and printing the removed value.

Uploaded by

Md Asif Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views2 pages

Queue Using Linked List

This C program implements a queue using a linked list data structure. It defines Node and front/rear pointers to track the queue. The enqueue function adds a new node to the rear, dequeue removes the front node and returns its data, and Display prints the queue. The main function tests it by enqueueing several values, displaying the queue, dequeueing and printing the removed value.

Uploaded by

Md Asif Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Queue using Linked List

#include <stdio.h>
#include <stdlib.h>

struct Node
{
int data;
struct Node *next;

}*front=NULL,*rear=NULL;

void enqueue(int x)
{
struct Node *t;
t=(struct Node*)malloc(sizeof(struct Node));
if(t==NULL)
printf("Queue is FUll\n");
else
{
t->data=x;
t->next=NULL;
if(front==NULL)
front=rear=t;
else
{
rear->next=t;
rear=t;
}
}

int dequeue()
{
int x=-1;
struct Node* t;

if(front==NULL)
printf("Queue is Empty\n");
else
{
x=front->data;
t=front;
front=front->next;
free(t);
}
return x;
}

void Display()
{
struct Node *p=front;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}

int main()
{
enqueue(10);
enqueue(20);
enqueue(30);
enqueue(40);
enqueue(50);

Display();

printf("%d ",dequeue());

return 0;
}

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