One can at least learn form the "std::list, std::sort and std::binary_search". For one, the std::list has its own 'sort' member function -- for a reason. We'll get to that a bit later.
First, both std::sort and std::list::sort do have a common feature: they take 'comp' as parameter. What is the 'comp'?
(Some) sorting algorithms do have:
1 2 3
|
if ( ! comp( A, B ) ) {
swap( A, B )
}
|
The 'comp' returns
true
, if the A and B are already in desired order. The rest of "std::sort and std::list::sort" have no say on the matter.
Therefore, the "
Create multiple sorting functions" means "
create multiple comp", if you do use std::sort or std::list::sort.
The code fragment above calls
swap
too. Something that exchanges the two values (if they weren't in right order). Swapping values is relatively trivial, but it involves copying a value. Value can be complex and the copy thus relatively expensive.
The linked list has an alternative option. It can swap the nodes that hold the values. If it does, then it has to update links, which is cheap but less easy to do correctly. std::sort is not aware about linked lists, but list::sort is.
"Database" sounds fancy, but what you really will have is a "list of records". You can define a record with struct/class.
It could be educational to write the program first with std::list and other std components. Then replace each component with one of your own. Most can be broken into independent subtasks.