Skip to content

Commit d17649e

Browse files
committed
add description
1 parent 4aa6d73 commit d17649e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Linked List/linked_list.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
# Implementation of Singly Linked List in Python
2+
'''
3+
This implementation defines a Node class to represent a node in the linked list, and a LinkedList
4+
class to represent the linked list itself. The LinkedList class has methods to insert nodes at the
5+
beginning or end of the list, delete nodes from the list, and print the list. Each node has two
6+
attributes: its data and a reference to the next node in the list (next).
7+
The LinkedList class has one attribute: the head node of the list (head). When a new node is
8+
inserted at the beginning of the list, its next attribute is set to the current head node, and the
9+
head attribute is set to the new node. When a new node is inserted at the end of the list, it is
10+
appended to the last node's next attribute. When a node is deleted, the list is traversed to find
11+
the node with the given data, and its next attribute is set to the node after it. Finally, the
12+
print_list method traverses the list and prints each node's data.
13+
'''
214
# Define a class to represent a node in the linked list
315
class Node:
416
def __init__(self, data):

0 commit comments

Comments
 (0)