Розмір відео: 1280 X 720853 X 480640 X 360
Показувати елементи керування програвачем
Автоматичне відтворення
Автоповтор
DLLNode *sortAKSortedDLL(DLLNode *head, int k) { priority_queue pq; DLLNode* tail = head; DLLNode* nexty = NULL; int freq = k + 1; while(tail && freq > 0){ pq.push(tail->data); tail = tail->next; nexty = tail; freq -= 1; } tail = head; while(nexty){ int minVal = pq.top(); pq.pop(); tail->data = minVal; tail = tail->next; pq.push(nexty->data); nexty = nexty->next; } while(tail && !pq.empty()){ int minVal = pq.top(); pq.pop(); tail->data = minVal; tail = tail->next; } return head; }
Issue from my side, i should also have added 5 in heap and processed the execution. Sorry for that ❤️
DLLNode *sortAKSortedDLL(DLLNode *head, int k) {
priority_queue pq;
DLLNode* tail = head;
DLLNode* nexty = NULL;
int freq = k + 1;
while(tail && freq > 0){
pq.push(tail->data);
tail = tail->next;
nexty = tail;
freq -= 1;
}
tail = head;
while(nexty){
int minVal = pq.top(); pq.pop();
tail->data = minVal;
tail = tail->next;
pq.push(nexty->data);
nexty = nexty->next;
}
while(tail && !pq.empty()){
int minVal = pq.top(); pq.pop();
tail->data = minVal;
tail = tail->next;
}
return head;
}
Issue from my side, i should also have added 5 in heap and processed the execution. Sorry for that ❤️