Skip to content

Commit 69ccd6a

Browse files
Update Single-linked-list-operations.py
1 parent 8b47d9a commit 69ccd6a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Data Structures/Linked Lists/Singly Linked List/Single-linked-list-operations.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
// A pythom program for all operations performed on singly linked-list.
2-
// Time-Complexity = O(n)
3-
// Space-Complexity = O(n)
1+
# A pythom program for all operations performed on singly linked-list.
2+
# Time-Complexity = O(n)
3+
# Space-Complexity = O(n)
44
class Node:
5-
def __init__(self, data=None, next=None): // Creation of Node
5+
def __init__(self, data=None, next=None): # Creation of Node
66
self.data = data
77
self.next = next
88

99
class LinkedList:
1010
def __init__(self):
11-
self.head = None // head points the first node
11+
self.head = None # head points the first node
1212

1313
def print(self):
1414
if self.head is None:
1515
print("Linked list is empty")
1616
return
1717
itr = self.head
18-
llstr = '' // empty string
18+
llstr = '' # empty string
1919
while itr:
2020
llstr += str(itr.data)+' --> ' if itr.next else str(itr.data)
2121
itr = itr.next
2222
print(llstr)
2323

24-
def length(self): // will calculate length of the linked list
24+
def length(self): # will calculate length of the linked list
2525
count = 0
2626
itr = self.head
2727
while itr:
@@ -31,7 +31,7 @@ def length(self): // will calculate length of the linked list
3131
return count
3232

3333
def insert_at_begining(self, data):
34-
node = Node(data, self.head) // Creating a new node calling Node method
34+
node = Node(data, self.head) # Creating a new node calling Node method
3535
self.head = node
3636

3737
def insert_at_end(self, data):
@@ -77,7 +77,7 @@ def remove_at(self, index):
7777
itr = self.head
7878
while itr:
7979
if count == index - 1:
80-
itr.next = itr.next.next // to delete the specified node
80+
itr.next = itr.next.next # to delete the specified node
8181
break
8282

8383
itr = itr.next

0 commit comments

Comments
 (0)