Question: //PLEASE WRITE A DRIVEN PROGRAM FOR THE CODE BRLOW //HERE VALUE FROM PROFESSOR //Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] Explanation: The linked-lists are: [ 1->4->5,

//PLEASE WRITE A DRIVEN PROGRAM FOR THE CODE BRLOW

//HERE VALUE FROM PROFESSOR

//Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] Explanation: The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into one sorted list: 1->1->2->3->4->4->5->6

//PLEASE SHOW ME THE OUTPUT

//DONOT SEND ME FAKE ANSWER

#include #include #include using namespace std; ///* Definition for singly-linked list. struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution { public: ListNode* mergeKLists(vector& lists) { priority_queue, greater> minHeap; for (auto list : lists) { while (list) { minHeap.push(list->val); list = list->next; } } ListNode* dummy = new ListNode(0); ListNode* curr = dummy; while (!minHeap.empty()) { curr->next = new ListNode(minHeap.top()); minHeap.pop(); curr = curr->next; } return dummy->next; } };

int main() { // TO DO

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!