Update Linked-list.md

chnage3
pull/615/head
Vinay Sagar 2024-05-26 14:24:19 +05:30 zatwierdzone przez GitHub
rodzic b2264d4e6f
commit a1dd770b20
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 6 dodań i 6 usunięć

Wyświetl plik

@ -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