File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 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
315class Node :
416 def __init__ (self , data ):
You can’t perform that action at this time.
0 commit comments