You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contrib/ds-algorithms/linked-list.md
+25-7
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Linked List Data Structure
2
2
3
-
Link list is a linear data Structure which can be defined as collection of objects called nodes that are randomly stored in the memory.
3
+
Linked list is a linear data Structure which can be defined as collection of objects called nodes that are randomly stored in the memory.
4
4
A node contains two types of metadata i.e. data stored at that particular address and the pointer which contains the address of the next node in the memory.
5
5
6
6
The last element in a linked list features a null pointer.
@@ -36,10 +36,10 @@ The smallest Unit: Node
36
36
Now, we will see the types of linked list.
37
37
38
38
There are mainly four types of linked list,
39
-
1. Singly Link list
40
-
2. Doubly link list
41
-
3. Circular link list
42
-
4. Doubly circular link list
39
+
1. Singly linked list
40
+
2. Doubly linked list
41
+
3. Circular linked list
42
+
4. Doubly circular linked list
43
43
44
44
45
45
## 1. Singly linked list.
@@ -160,6 +160,18 @@ check the list is empty otherwise shift the head to next node.
160
160
temp.next =None# Remove the last node by setting the next pointer of the second-last node to None
161
161
```
162
162
163
+
### Reversing the linked list
164
+
```python
165
+
defreverseList(self):
166
+
prev =None
167
+
temp =self.head
168
+
while(temp):
169
+
nextNode = temp.next #Store the next node
170
+
temp.next = prev #Reverse the pointer of current node
171
+
prev = temp #Move `prev` one step forward
172
+
temp = nextNode #Move `temp` one step forward.
173
+
self.head = prev #Update the head pointer to last node
174
+
```
163
175
164
176
### Search in a linked list
165
177
```python
@@ -174,6 +186,8 @@ check the list is empty otherwise shift the head to next node.
174
186
returnf"Value '{value}' not found in the list"
175
187
```
176
188
189
+
Connect all the code.
190
+
177
191
```python
178
192
if__name__=='__main__':
179
193
llist = LinkedList()
@@ -197,13 +211,17 @@ check the list is empty otherwise shift the head to next node.
0 commit comments