Answer the question
In order to leave comments, you need to log in
Internal sort. What is the best way to sort by multiple fields?
In short, let's say we have N records of the form:
struct Node {
string a, b;
int c, d, e;
};
Answer the question
In order to leave comments, you need to log in
Why not make a simple procedure for comparing objects of type Node? usually it is implemented by the cmp function or built-in "magic" methods, as in python.
And then feed this comparing function into the sort function as one of the parameters.
Similarly, you can use the result of this function when building a binary tree in order to decide which subtree the current vertex should belong to.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question