#include <iostream>
using namespace std;

void printArray(int arr[], int n){
    cout << "----- Printing Array -----" << endl;
    for(int i=0; i<n; i++){
        cout << arr[i] << " ";
    }
    cout << endl << endl;
}

void sortNums(int arr[], int n){
    int i = 0, j = n-1;
    
    while(i < j){
        while(arr[i] == 0){
            i++;
        }
        while(arr[j] == 1){
            j--;
        }
        if(arr[i] == 1 && arr[j] == 0 && i<j){
            swap(arr[i], arr[j]);
            i++;
            j--;
        }
    }
}

int main() {
    int arr[11] = {1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1};
    
    sortNums(arr, 11);
    printArray(arr, 11);
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: