Sorting structs?
Boomerang
nomailforme at nomailforme.no
Wed Jan 29 01:33:49 PST 2014
Hello everybody. I'm trying to learn D by solving simple
exercises.
The current exercise: read names and grades of students, then
print the names of students in descending order of their grades.
In C++, I would define a Student struct, overload the operators:
bool operator<(const Student&, const Student&)
std::istream& operator>>(std::istream&, Student&)
Then I'd store the Students in let's say a std::vector, sort it
in reverse, then print it accordingly.
But I don't know how to do things in D. I'm reading Cehreli's
book, so far I've only finished its first trinity (just before
struct).
I would appreciate it if you explained your approach and gave
source code illustrating it. Thanks!
More information about the Digitalmars-d-learn
mailing list