This repository contains the implementation of a Singly Linked List from scratch in Java. The project has multiple components including the Node
class, SinglyLinkedList
class, input handling, and operations like insertion, deletion, traversal, search, and list reversal.
- Introduction
- Features
- Installation
- Running the Application
- Project Structure
- How to Use
- Contributors
This project demonstrates how to implement a Singly Linked List data structure in Java. The linked list is composed of nodes, each containing data and a reference to the next node. The project supports the following operations:
- Adding nodes (at the head, tail, or specific position)
- Removing nodes (by value or position)
- Traversing the list
- Searching for elements
- Reversing the list
- Node Class: Represents individual nodes in the list.
- Singly Linked List Class: Contains methods for adding, removing, searching, and reversing the list.
- Input Handler: A user-friendly interface to interact with the list from the console.
- File Structure: The project is divided into multiple Java files for better modularity and organization.
Make sure you have the following installed on your system:
- Java Development Kit (JDK) (version 8 or higher)
- Visual Studio Code (VSCode) or any preferred IDE
- Git for version control
-
Open a terminal or command prompt.
-
Navigate to the directory where you want to clone the project.
-
Run the following command:
git clone https://github.com/SyntaxIDK/singly-linked-list-java.git
-
Change into the cloned repository's directory:
cd singly-linked-list-java
-
Open Visual Studio Code.
-
Click on File > Open Folder... and select the project folder (
singly-linked-list-java
). -
Make sure the Java extension pack is installed in VSCode if not already:
- Go to Extensions (from the sidebar).
- Search for
Java Extension Pack
. - Install it.
-
Once the folder is opened, you should be able to see all the Java files (
Node.java
,SinglyLinkedList.java
,InputHandler.java
,Main.java
) in the Explorer on the left sidebar.
To run the application in Visual Studio Code:
-
Make sure the
Main.java
file is opened. -
You can run the program by clicking the Run button at the top right of the VSCode interface or by using the terminal:
-
Click Terminal > New Terminal from the menu.
-
In the terminal, navigate to the
src
folder (where the.java
files are located). -
Compile the code using the command:
javac com/example/*.java
-
Run the compiled code:
java com.example.Main
-
-
The application will start in the terminal, and you will be able to interact with the singly linked list by choosing options (like adding/removing nodes, traversing, etc.).
singly-linked-list-java/
│
├── src/
│ ├── com/example/
│ │ ├── Node.java # Node class representing each node in the list
│ │ ├── SinglyLinkedList.java # Singly Linked List class with all operations
│ │ ├── InputHandler.java # Handles user input to interact with the list
│ │ └── Main.java # Entry point of the program
│
└── README.md # This README file
Once the program is running, you will see a menu in the terminal that looks like this:
Choose an option:
1. Add at Head
2. Add at Tail
3. Add at Position
4. Remove by Value
5. Remove by Position
6. Display List
7. Search for Element
8. Reverse List
9. Exit
You can enter the corresponding number to perform actions on the singly linked list. For example:
- Press
1
to add a node at the head. - Press
2
to add a node at the tail. - Press
3
to add a node at a specific position. - Press
4
to remove a node by its value. - Press
5
to remove a node by its position. - Press
6
to traverse and display the entire list. - Press
7
to search for an element. - Press
8
to reverse the list. - Press
9
to exit.
Follow the prompts to input data or perform operations as needed.
This project is a collaborative effort. Special thanks to the group members for their contributions.
- Kaveesha
- will be added