| 10 | |
| 11 | # Constructor to initialize the node object |
| 12 | class LinkedList: |
| 13 | # Function to initialize head |
| 14 | def __init__(self): |
| 15 | self.head = None |
| 16 | self.tail = None |
| 17 | |
| 18 | # Method to print linked list |
| 19 | def printList(self): |
| 20 | temp = self.head |
| 21 | |
| 22 | while temp: |
| 23 | print(temp.data, end="->") |
| 24 | temp = temp.next |
| 25 | |
| 26 | # Function to add of node at the end. |
| 27 | def append(self, new_data): |
| 28 | new_node = Node(new_data) |
| 29 | |
| 30 | if self.head is None: |
| 31 | self.head = new_node |
| 32 | self.tail = new_node |
| 33 | return |
| 34 | self.tail.next = new_node |
| 35 | self.tail = self.tail.next |
| 36 | |
| 37 | |
| 38 | # Function to merge two sorted linked list. |