This project implements a Singly Linked List in Python. It includes functionalities such as inserting and removing nodes at both the beginning and the end, inserting at a specific index, counting nodes, and printing the entire list in a readable format.
- Insert at Beginning: Adds a node to the start of the list.
- Insert at End: Adds a node to the end of the list.
- Insert at Index: Inserts a node at a specific index.
- Pop from Beginning: Removes the first node and returns its value.
- Pop from End: Removes the last node and returns its value.
- Count Nodes: Returns the total number of nodes in the list.
- Print List: Prints the linked list in a human-readable format.
-
Insert_At_Beginning(Value)Inserts a new node with the given Value at the beginning of the list. -
Insert_At_End(Value)Inserts a new node with the given Value at the end of the list. -
Insert_At_index(index, Value)Inserts a new node with the given Value at the specified index. -
Pop_From_Beginning()Removes and returns the value of the first node in the list. -
Pop_From_End()Removes and returns the value of the last node in the list. -
Count_LinkedList()Returns the total number of nodes in the linked list. -
Print_Linked_List()Prints the entire linked list in a human-readable format like:Value1 ===> Value2 ===> Value3
1.Clone the repository:
git clone https://github.com/yourusername/LinkedList
2.Run the Python script:
python linked_list.py
LL1 = LinkedList()
# Insert at Beginning
LL1.Insert_At_Beginning(10)
LL1.Insert_At_Beginning(15)
LL1.Print_Linked_List()
# Insert at End
LL1.Insert_At_End(30)
LL1.Print_Linked_List()
# Pop from End
LL1.Pop_From_End()
LL1.Print_Linked_List()
# Count Nodes
print(f"Total Nodes: {LL1.Count_LinkedList()}")
This project is licensed under the MIT License.