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 #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started