• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Queues using Linked list in Data Structures

Queues using Linked list

It configures storage (using arrays), queues where harder to manipulate then were stacks.

It causes difficulties to handle full queues and empty queues. It is for queues that linked storage really comes into its own

The linked implementation has two advantages over the array implementation (1) it is faster locations for insertion and deletion are same at the back and at the front and 2) it wastes no space

Linked queues are just as easy to handle as are linked stacks.

 

45

 

Program:

Program to implement queue using linked list :

# include<stdio.h>

#include<conio.h>

#include<stdio.h>

struct node

{

int data;

struct node *next;

};

struct node *front=NULL ;*rear;

void insertion()

{

int els;

struct node *new node;

new node=(struct node *)malloc(sizeof(struct node));

printf(“Enter data for new node: ”);

scanf(“%d”,&ele);

newnode 7data=ele;

newnode 7next=NULL;

if(front==NULL)

{

front=new node;

rear=front;

}

else

{

rear7 next= new code;

rear= new node;

}

}

void deletion()

{

struct node *temp;

if(front==NULL)

printf(“QUEUE underflow”);

else

{

temp=front;

front=front 7 next;

printf(“Deleted element is : %d \n”, temp 7 data);

free(temp);

}

}

void display()

{

struct node *ptr;

if(front===NULL)

printf(“queue is empty”);

else

{

printf(“elements of queue are :”);

for(ptr=front; ptr!=NULL;ptr=ptr7next);

printf(“%5d”,ptr7 data);

}

}

void main()

{

int ch;

clrscr();

do

{

printf(“1. INSERTION \n”);

printf(“2. DELETION \n”);

printf(“3. DISPLAY \n”);

printf(“4.EXIT \n”);

printf(“Enter U r choice :”);

scanf(“%d”,&ch);

switch(ch)

{

case1: insertion(); break;

case2: deletion(); break;

case3: display(); break;

case 4: exit(0);

}

} while(ch<=4)

getch();

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Summary
Review Date
Reviewed Item
Queues using Linked list in Data Structures
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Queues using Linked list in Data Structures"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.