| 5 | |
| 6 | |
| 7 | class Reverse_Linked_List: |
| 8 | def __init__(self): |
| 9 | self.head = None |
| 10 | |
| 11 | def Insert_At_End(self, new_data): |
| 12 | new_node = Node(new_data) |
| 13 | if self.head is None: |
| 14 | self.head = new_node |
| 15 | return |
| 16 | current = self.head |
| 17 | while current.next: |
| 18 | current = current.next |
| 19 | current.next = new_node |
| 20 | |
| 21 | def Reverse_list_Groups(self, head, k): |
| 22 | count = 0 |
| 23 | previous = None |
| 24 | current = head |
| 25 | while current is not None and count < k: |
| 26 | following = current.next |
| 27 | current.next = previous |
| 28 | previous = current |
| 29 | current = following |
| 30 | count += 1 |
| 31 | if following is not None: |
| 32 | head.next = self.Reverse_list_Groups(following, k) |
| 33 | return previous |
| 34 | |
| 35 | def Display(self): |
| 36 | temp = self.head |
| 37 | while temp: |
| 38 | print(temp.data, "->", end=" ") |
| 39 | temp = temp.next |
| 40 | print("None") |
| 41 | |
| 42 | |
| 43 | if __name__ == "__main__": |
no outgoing calls
no test coverage detected