# 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]

## Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.

## Using isdigit() in C/C++

In this article, we'll take a look at using the isdigit() function in C/C++. This is a very simple way to check if any value is a digit or not. Let's look

## C++ Tutorial for Beginners 19 - C++ Structures | Struct declaration | C++ Data Structures

Welcome to this course on C++ Tutorial for Beginners. In this video we will see How to use C++ Structures.

## Object Oriented Programming in C++ | C++ OOPs Concepts | Learn Object Oriented C++

C++ is general purpose, compiled, object-oriented programming language and its concepts served as the basis for several other languages such as Java, Python, Ruby, Perl etc.