Question: In this problem, you will use heap to solve a common interview question: Merge sorted lists. Given k linked lists of integer, which are already
In this problem, you will use heap to solve a common interview question: Merge sorted lists.
Given k linked lists of integer, which are already sorted in descending order. Your task is to merge them to one single linked list, and sorted them in descending order. For example, if you are given linked lists: [10, 6, 4, 1], [13, 7, 2], [9, 5, 3, 2, 1], the example output should be [13, 10, 9, 7, 6, 5, 4, 3, 2, 2, 1, 1].
You should use only one heap to solve this problem. HINT: When you push all the head nodes of those linked lists into a max heap, the top node of the heap must be the largest node (the head node of the result linked list).
Useful heap operation: top(), pop(), push(element).
Code in main.cpp:


1 #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
