0% found this document useful (0 votes)
14 views5 pages

1005 Assignment-9

This program implements a queue using a linked list in Java. It allows users to add elements to the rear of the queue, remove from the front, and view all elements through a menu-driven interface. The program maintains this cycle until the user chooses to exit, demonstrating fundamental queue operations through a linked list approach.

Uploaded by

chinmaydalvi004
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)
14 views5 pages

1005 Assignment-9

This program implements a queue using a linked list in Java. It allows users to add elements to the rear of the queue, remove from the front, and view all elements through a menu-driven interface. The program maintains this cycle until the user chooses to exit, demonstrating fundamental queue operations through a linked list approach.

Uploaded by

chinmaydalvi004
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/ 5

Assignment-9

Name: Pranav Bafna

Roll No: 221005

Batch: A1

Problem Statement:
Write a Java Program to perform
implementation of Queue using Linked List
a. Enqueue.
b. Dequeue.
c. Display.

:
1. This program is designed to create a queue by leveraging the flexibility of a linked list data
structure.
2. Users can seamlessly add elements to the rear of the queue, remove elements from the
front, and effortlessly view the entire queue.
3. The program maintains this cycle of operations until the user decides to gracefully exit.

1.Import Statements:The program begins by importing necessary Java classes such as


`LinkedList`, `Queue`, and `Scanner` for implementing a queue and handling user input.

2.Menu-Driven Interface:The main method provides a user-friendly menu with options to


enqueue, dequeue, display elements, and exit the program.

3. Queue Operations: The program defines methods for enqueueing (adding to the rear),
dequeuing (removing from the front), and displaying elements in the queue.

4.User Interaction:A `Scanner` object captures user input for menu choices and element values,
ensuring interactive communication with the program.

5.Graceful Exit: The program allows users to exit gracefully, displaying a termination message
before ending the execution.
Algorithm:
1.Node Representation: Develop a class named `QNode` to symbolize a node within the
linked list, where each node holds an integer data value and a reference to the next
node.

2.Queue Management Class: Establish a class called `QLL` to oversee queue operations
using linked list functionality.

3. Enqueue Operation:Implement an `enqueue` method, accepting user input through a


`Scanner`, to seamlessly add an element to the rear of the queue.

4. Dequeue Operation:Create a `dequeue` method to efficiently remove an element


from the front of the queue.

5. Display Operation: Define a `display` method for presenting all elements currently
residing in the queue.

6. Initialization in Main Method:Within the main method, instantiate an object of the


`QLL` class and initialize a `Scanner` to facilitate user input.

7. User Menu Loop: Utilize a loop structure to consistently offer a menu to the user,
allowing them to enqueue, dequeue, display, or exit based on their selection.

8. Loop Continuation:Ensure the loop persists until the user explicitly opts to exit
(choosing option 0), providing a continuous and interactive user experience.

Code:
Output:
Conclusion:
1. This Java code demonstrates the fundamental operations of a queue implemented with a
linked list, shedding light on essential data structure maneuvers.
2. Through a user-friendly command-line interface, individuals can effortlessly enqueue,
dequeue, and display elements within the queue.
3. Serving as a foundational educational tool, the code offers insight into working with queues
and linked lists in the Java programming language.
4. In a production environment, it's imperative to enhance the code with features such as error
handling and input validation to guarantee resilience and dependability.

You might also like