possible to move zeros to the end of the array using only std::sort()?

possible to move zeros to the end of the array using only std::sort()?

I am working on this question: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.

I am working on this question: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.

I know how to answer this question by just doing in-place swapping but I also would want to see if it is possible to solve it with std::sort

according to cplusplus.com: the comparator function for the sort function is a Binary function that accepts two elements in the range as arguments, and returns a value convertible to bool. The value returned indicates whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines. The function shall not modify any of its arguments. This can either be a function pointer or a function object.

//comments below are based on my understanding
static bool comp(int a, int b){
    //lambda function evaluates to true - no swap, 
    //evaluates to false -swap
    if(a==0) return false;
    if(b==0) return true;
    //if neither a nor b is 0 them do not swap
    return true;
}

void moveZeroes(vector<int>& nums) { sort(nums.begin(),nums.end(),comp); }

the given test case is [0,1,0,3,12] my output is [12,3,1,0,0]

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Variable Introduction in C#[Bangla]

LIKE | COMMENT | SHARE | SUBSCRIBE A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...