You are viewing a single comment's thread. Return to all comments →
def listToArray(head): current = head result = [] while current: result.append(current.data) current = current.next return result def sortedArray(arr): result = [] for data in arr: inserted = False for i in range(len(result)): if data < result[i]: result.insert(i, data) inserted = True break if not inserted: result.append(data) return result def convertList(sorted): llist3 = SinglyLinkedList() for data in sorted: llist3.insert_node(data) return llist3.head def mergeLists(head1, head2): arrA = listToArray(head1) arrB = listToArray(head2) concatArr = arrA+arrB sorted = sortedArray(concatArr) linkedlist = convertList(sorted) return linkedlist
Seems like cookies are disabled on this browser, please enable them to open this website
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →