Is this in linear time and constant space? (sort array, so that all 0s are at the end, other numbers are at front (solution))

  c++

The problem: You are given an array of a bunch of numbers and zeros, sort it so that all the numbers that are not zero, are at the front, and all the numbers at the end are zeros.

Question: Does my solution run in Linear time ? Or not ? Also is it constant space or not?

#include <iostream>
#include <vector>
#include <stack>
using namespace std;

int main()
{
    cin.tie(0);
    std::ios_base::sync_with_stdio(false);

    vector<int> MyVec;
    int input;
    int i = 0;
    stack<int> mystack;
    stack<int> zerostack;
    while((input = getchar())&& (input!=10))
    {
        if(input != 32)
        {
            MyVec.push_back(input - '0');

            if(MyVec[i] == 0)
                zerostack.push(MyVec[i]);
            else
                mystack.push(MyVec[i]);

            i++;
        }
    }
    MyVec.clear();
    while(!mystack.empty())
    {
         MyVec.push_back(mystack.top());
         mystack.pop();
    }
    while(!zerostack.empty())
    {
         MyVec.push_back(zerostack.top());
         zerostack.pop();
    }
    for(auto a : MyVec)
        cout << a << " ";

    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT