0% found this document useful (0 votes)
2 views

Queueusinglinkedlist

This document contains a C program that implements a simple queue using a linked list. It includes functions for creating nodes, enqueueing and dequeueing elements, and displaying the queue. The main function provides a user interface to interact with the queue through a menu-driven approach.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Queueusinglinkedlist

This document contains a C program that implements a simple queue using a linked list. It includes functions for creating nodes, enqueueing and dequeueing elements, and displaying the queue. The main function provides a user interface to interact with the queue through a menu-driven approach.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
#include <stdlib.h>
typedef struct Node {
int data;
struct Node* next;
} NODE;
NODE* createnode(int data) {
NODE* newnode = (NODE*)malloc(sizeof(NODE));
newnode->next = NULL;
newnode->data = data;
return newnode;
}
void enqueue(NODE** start, int data) {
NODE* newnode = createnode(data);
if (*start == NULL) {
*start = newnode;
return;
}
NODE* temp = *start;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = newnode;
}
void dequeue(NODE** start) {
if (*start == NULL) {
printf("Nothing to delete\n");
return;
}
NODE* temp = *start;
*start = temp->next;
free(temp);
}
void display(NODE** start) {
if (*start == NULL) {
printf("Nothing to Display\n");
return;
}
NODE* temp = *start;
while (temp != NULL) {
printf("%d\t", temp->data);
temp = temp->next;
}
printf("\n");
}
int main() {
int option, item;
NODE* start = NULL;

do {
printf("\nEnter your option\n1.Enqueue\n2.Dequeue\n3.Display\n4.Exit\n");
scanf("%d", &option);
switch (option) {
case 1:
printf("Enter the element\n");
scanf("%d", &item);
enqueue(&start, item);
break;
case 2:
dequeue(&start);
break;
case 3:
display(&start);
break;
case 4:
printf("Exiting...\n");
break;
default:
printf("Enter a valid option\n");
break;
}
} while (option != 4);
return 0;
}

You might also like