fork download
  1. class Solution {
  2. public:
  3. void pushZerosToEnd(vector<int>& a)
  4. {
  5.  
  6. int n = a.size();
  7.  
  8. int i = 0;
  9. int j = 0;
  10.  
  11. while (j < n)
  12. {
  13. if (a[j] != 0) // means non zero element
  14. {
  15. swap(a[i], a[j]);
  16. i = i + 1;
  17. j = j + 1;
  18. }
  19. else
  20. {
  21. j = j + 1; // Element is zero move only 'j' pointer
  22. }
  23. }
  24.  
  25. return;
  26.  
  27. }
  28. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:25: error: ‘vector’ has not been declared
     void pushZerosToEnd(vector<int>& a)
                         ^~~~~~
prog.cpp:3:31: error: expected ‘,’ or ‘...’ before ‘<’ token
     void pushZerosToEnd(vector<int>& a)
                               ^
prog.cpp: In member function ‘void Solution::pushZerosToEnd(int)’:
prog.cpp:6:17: error: ‘a’ was not declared in this scope
         int n = a.size();
                 ^
prog.cpp:15:17: error: ‘swap’ was not declared in this scope
                 swap(a[i], a[j]);
                 ^~~~
stdout
Standard output is empty