Skip to content

Commit c37bc7f

Browse files
committed
Implement q_descend using q_ascend and reversal
Previously, q_descend was a placeholder and did nothing. Now it correctly removes nodes that violate descending order by reusing q_ascend with two queue reversals. This approach leverages the logic of q_ascend logic first reversing the queue, applying q_ascend to remove non-decreasing elements, and then reversing it back to restore the original order. Change-Id: I00e4450e1e2605c204b4ab2cbba9fbb905f43e3d
1 parent 6c2c172 commit c37bc7f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

queue.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ int q_ascend(struct list_head *head)
219219
int q_descend(struct list_head *head)
220220
{
221221
// https://leetcode.com/problems/remove-nodes-from-linked-list/
222-
return 0;
222+
q_reverse(head);
223+
q_ascend(head);
224+
q_reverse(head);
225+
return q_size(head);
223226
}
224227

225228
/* Merge all the queues into one sorted queue, which is in ascending/descending

0 commit comments

Comments
 (0)