Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void writeOnConsole(int * array, int arraySize) {
- for (int i = 0; i < arraySize;i++)
- cout << array[i] << ", ";
- cout << array[arraySize] << endl;
- }
- int main() {
- int array[] = {3, 2, 0, 4, 8, 0, 5, 9, 0, 11, 0, 45, 0, 23, 21, 0, 36};
- int arraySize = sizeof(array)/sizeof(int) - 1;
- int write = arraySize;
- for (int read = arraySize; read >= 0; read--)
- if(array[read] == 0)
- continue;
- else
- array[write--] = array[read];
- // clear trash
- while ( write >= 0 ) {
- array[write] =0;
- write--;
- }
- writeOnConsole(array, arraySize);
- return 0;
- }
Add Comment
Please, Sign In to add comment