Guest User

Untitled

a guest
Mar 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void writeOnConsole(int * array, int arraySize) {
  5. for (int i = 0; i < arraySize;i++)
  6. cout << array[i] << ", ";
  7. cout << array[arraySize] << endl;
  8. }
  9.  
  10. int main() {
  11. int array[] = {3, 2, 0, 4, 8, 0, 5, 9, 0, 11, 0, 45, 0, 23, 21, 0, 36};
  12. int arraySize = sizeof(array)/sizeof(int) - 1;
  13. int write = arraySize;
  14.  
  15. for (int read = arraySize; read >= 0; read--)
  16. if(array[read] == 0)
  17. continue;
  18. else
  19. array[write--] = array[read];
  20.  
  21. // clear trash
  22. while ( write >= 0 ) {
  23. array[write] =0;
  24. write--;
  25. }
  26.  
  27. writeOnConsole(array, arraySize);
  28. return 0;
  29. }
Add Comment
Please, Sign In to add comment