| 5 | |
| 6 | |
| 7 | class Circular_Linked_List: |
| 8 | def __init__(self): |
| 9 | self.head = None |
| 10 | |
| 11 | def Push(self, data): |
| 12 | temp = Node(data) |
| 13 | temp.next = self.head |
| 14 | temp1 = self.head |
| 15 | if self.head is not None: |
| 16 | while temp1.next is not None: |
| 17 | temp1 = temp1.next |
| 18 | temp1.next = temp |
| 19 | else: |
| 20 | temp.next = temp |
| 21 | self.head = temp |
| 22 | |
| 23 | def Split_List(self, head1, head2): |
| 24 | if self.head is None: |
| 25 | return |
| 26 | slow_ptr = self.head |
| 27 | fast_ptr = self.head |
| 28 | while fast_ptr.next != self.head and fast_ptr.next.next != self.head: |
| 29 | fast_ptr = fast_ptr.next.next |
| 30 | slow_ptr = slow_ptr.next.next |
| 31 | if fast_ptr.next.next == self.head: |
| 32 | fast_ptr = fast_ptr.next |
| 33 | head1 = self.head |
| 34 | slow_ptr.next = head1 |
| 35 | if self.head.next != self.head: |
| 36 | head2.head = slow_ptr.next |
| 37 | fast_ptr.next = slow_ptr.next |
| 38 | |
| 39 | def Display(self): |
| 40 | temp = self.head |
| 41 | if self.head is not None: |
| 42 | while temp: |
| 43 | print(temp.data, "->", end=" ") |
| 44 | temp = temp.next |
| 45 | if temp == self.head: |
| 46 | print(temp.data) |
| 47 | break |
| 48 | |
| 49 | |
| 50 | if __name__ == "__main__": |
no outgoing calls
no test coverage detected