@@ -14,23 +14,24 @@ def print_forward(self):
1414 raise Exception ("The linked list is empty" )
1515
1616 current_node = self .head
17- ll_str = ""
17+ ll_str = str ( self . head . data )
1818 while current_node :
19- ll_str += str ( current_node . data ) + ' -->' + str (current_node .next .data ) if current_node .next else None
19+ ll_str += ' --> ' + str (current_node .next .data ) if current_node .next else ""
2020 current_node = current_node .next
21- print (ll_str )
21+ print ("Linked List:" , ll_str )
22+
2223 def print_backward (self ):
2324 if self .head is None :
2425 raise Exception ("The linked list is empty" )
2526 current_node = self .head
2627 ll_str = ""
2728 while current_node :
2829 if current_node .next :
29- ll_str += str (current_node .next . data ) + str ( current_node . data )
30+ ll_str += str (current_node .data ) + ' <-- '
3031 else :
3132 ll_str += "" + str (current_node .data )
3233 current_node = current_node .next
33- print (ll_str )
34+ print ("Link list in reverse: " , ll_str )
3435
3536 def get_last_node (self ):
3637 if self .head is None :
@@ -85,11 +86,23 @@ def insert_at(self, index, data):
8586 curr_node .next = new_node
8687 return
8788 curr_node = curr_node .next
89+
8890 def remove_at (self , index ):
89- return
91+ if index < 0 or index > self .get_length ():
92+ raise Exception ("Invalid index had been given !!" )
93+ if self .head is None :
94+ raise Exception ("The list is empty !!" )
95+ curr_ind = 0
96+ curr_node = self .head
97+ while curr_node :
98+ if curr_ind == index - 1 :
99+ curr_node .next = curr_node .next .next
100+ return
101+ curr_node = curr_node .next
90102
91103 def insert_values (self , data_list ):
92- return
104+ for data in data_list :
105+ self .insert_at_end (data )
93106
94107
95108if __name__ == '__main__' :
0 commit comments