vector<int> v = {50, -10, 20, -30};
sort(v.begin(), v.end()); // the default sort
// now v should be { -30, -10, 20, 50 }
// sort by absolute value:
sort(v.begin(), v.end(), [](int a, int b) { return abs(a)<abs(b); });
// now v should be { -10, 20, -30, 50 }
Code Example |
---|
Cpp :: reverse string c++ |
Cpp :: access part of string in c++ |
Cpp :: how to get length of a file in c++ |
Cpp :: c++ construnctor |
Cpp :: c++ string to int conversion |
Cpp :: for loop with array c++ |
Cpp :: c++ nested switch statements |
Cpp :: insert vector to end of vector c++ |
Cpp :: two pointer in c++ |
Cpp :: c++ console color |
Cpp :: How to reverse a string in c++ using reverse function |
Cpp :: return array from function c++ |
Cpp :: cpp float to string |
Cpp :: C++ std::string find and replace |
Cpp :: memcpy library cpp |
Cpp :: c++ for else |
Cpp :: log base 10 c++ |
Cpp :: binary representation c++ |
Cpp :: matrix in vector c++ |
Cpp :: lutris |
Cpp :: find index of element in array c++ |
Cpp :: int to hexadecimal in c++ |
Cpp :: what is thread in c++ |
Cpp :: stoi function in c++ library |
Cpp :: See Compilation Time in c++ Program |
Cpp :: pragma cpp |
Cpp :: cpp float |
Cpp :: if statement c++ |
Cpp :: c++ operator overloading |
Cpp :: cpp lambda function |