QUEUE USING LINKED LIST

568

queue using linked list

BCA THird semester

Data Structure’

 

 

#include <stdlib.h>
struct node {
int data;
struct node *link;
};
struct node *temp,*front, *rear; /* Global Declarations */

void Insert(int);
int Delete();
void Display();

main() {
/* Main Program */
int opn, elem;
front = rear = NULL;
do {
clrscr();
printf(“\n1. Insertion \n2. Deletion\n3. Display\n4. Exit\n”);
printf(“\nEnter your option : “);
scanf(“%d”, &opn);
switch (opn) {
case 1:
clrscr();
printf(“\nEnter Item : “);
scanf(“%d”, &elem);
Insert(elem);
break;
case 2:
clrscr();
elem = Delete();
if (elem != -1)
printf(” Deleted Node(From Front)with the Data: %d\n”, elem);
break;
case 3:
clrscr();
printf(“Linked List Implementation of Queue: Status:\n”);
Display();
break;
case 4:
clrscr();
printf(“\n\n Terminating \n\n”);
break;
default:
printf(“\n\nInvalid Option !!! Try Again !! \n\n”);
break;
}
getch();
} while (opn != 4);
}

void Insert(int info)
{
temp = (struct node *) malloc(sizeof(struct node));
temp->data = info;
temp->link = NULL;
if (front == NULL)
{
front = rear = temp;
}
else {
rear->link = temp;
rear = temp;

}
}

int Delete() {
int info;
// struct node *t;
if (front == NULL) {
printf(” Underflow!!!”);
return -1;
} else {
temp = front;
info = front->data;
if (front == rear)
rear = NULL;
front = front->link;
temp->link = NULL;
free(temp);
return (info);
}
}

void Display()
{
if (front == NULL)
printf(“Empty Queue\n”);
else
{
temp = front;
while (temp)
{
printf(“%d\n”, temp->data);
temp = temp -> link;
}
}
}

 

 

 

 

OUTPUT
1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 1
Enter Item : 10

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 1
Enter Item : 20

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 1
Enter Item : 30

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 1
Enter Item : 40

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 1
Enter Item : 50

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 3
Linked List Implementation of Queue: Status:
10
20
30
40
50

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 2
Deleted Node(From Front)with the Data: 10

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 2
Deleted Node(From Front)with the Data: 20

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 2
Deleted Node(From Front)with the Data: 30

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 2
Deleted Node(From Front)with the Data: 40

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 2
Deleted Node(From Front)with the Data: 50

1. Insertion
2. Deletion
3. Display
4. Exit
Enter Your Choice : 2
OUEUE EMPTY

 

 

 

if you liike share with own friends

 

if you need a Downloadable link once message us on-page you can get at a time.

m.me/bcanotesnepal

This post is posted for not further third-party purposes.

Copyright By:-  Bcanotesneapl

Not allowed to upload these notes to other sites.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

if you want to download this PDF comment on us we will provide you a downloadable link.

if you like please share this post with your friend who studies in BCA

if you have any query please comment below,

if you like our sites. you can visit again for the latest updates notes of different BCA subjects of Presentation and different topics with assignment questions and solutions.

Don’t forget to like our page and post also share with your friend and having your group.

if you have any questions you can drop or share them with me using the comment box I will try to answer your question.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

LEAVE A REPLY

Please enter your comment!
Please enter your name here