Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ sort numbers by magnitude/absolute value

// sort numbers by their magnitude value
bool sortByAbsolute(int a, int b) {
    return abs(a) < abs(b);
}

void find(std::vector<int> &nums, std::vector<int> &sorted) {
    std::sort(nums.begin(), nums.end(), sortByAbsolute);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sort #numbers
ADD COMMENT
Topic
Name
6+7 =