File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 1
1
# 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
+ '''
2
14
# Define a class to represent a node in the linked list
3
15
class Node :
4
16
def __init__ (self , data ):
You can’t perform that action at this time.
0 commit comments