diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index 147527b..541410c 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -25,12 +25,12 @@ Let's code something The smallest Unit: Node - ```python +```python class Node: def __init__(self, data): self.data = data # Assigns the given data to the node self.next = None # Initialize the next attribute to null - ``` +``` Now, we will see the types of linked list. @@ -46,20 +46,20 @@ There are mainly four types of linked list, Simply think it is a chain of nodes in which each node remember(contains) the addresses of it next node. ### Creating a linked list class - ```python +```python class LinkedList: def __init__(self): self.head = None # Initialize head as None - ``` +``` ### Inserting a new node at the beginning of a linked list - ```python +```python def insertAtBeginning(self, new_data): new_node = Node(new_data) # Create a new node new_node.next = self.head # Next for new node becomes the current head self.head = new_node # Head now points to the new node - ``` +``` ### Inserting a new node at the end of a linked list