2 ms·
> By the way, will your C++ code work with singly-linked lists? Yes, but you'll use merge instead: list.merge(std::forward_list<T>{val}); I chose to use
by kccqzy 7y ago
> By the way, will your C++ code work with singly-linked lists?
Yes, but you'll use merge instead:
list.merge(std::forward_list<T>{val});
I chose to use std::lower_bound for binary search. If you are content with linear search like in the C example, you can even write a single function that works for both doubly linked lists and singly linked lists.
> Also, look: your C++ example calls four methods. The C code calls only one (malloc), all the rest is core language. It's 4:1 ratio for extra complexity.
This is what I call unnecessary manual inlining and reinventing the wheel for no good reason.
- jstimpfle 7y agoBinary search on a list??