sorting using algorithm

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
New poster
Posts: 3
Joined: Sat Jan 19, 2008 5:28 am

sorting using algorithm

Post by shiggy »

Is this the correct way to use sort?

Code: Select all

//include files (iostream, algorithm, vector, etc.)
class C
   bool operator < (const C& r) const
       if (some_attribute < r.some_attribute)
          return true;
          return false;

int main()
  vector<C> units;
  sort(units.begin(), units.end());
I ask this becuase many times I will implement a program using sort() and get a WA, but when I use a sorting method of my own (bubble sort), the program gets accepted.

Any ideas?

Learning poster
Posts: 51
Joined: Tue Sep 04, 2007 2:12 pm
Location: Russia, Saratov

Post by maxdiver »

I use standard sort() always, and I never had any problems.

Post Reply

Return to “C++”