Question: Given an array A, push all the zeros of the array to the front. The order of all other elements should remain same. Write a

Given an array A, push all the zeros of the array to the front. The order of all other elements should remain same.

Write a function: void pushZero(int[] A)

that accepts an integer array A. The function should convert the original array as per above requirement.

Input 10 2 0 3 4 0 4 0 10 9 0

where,

First line represents size of an array N.

Second line represents array elements. There must be single space between each element.

There should be one space after the last element.

Output 0 0 0 0 2 3 4 4 10 9

There must be single space between each element of output array.

There should be one space after the last element.

N is an integer within the range [1 to 1,000,000].

This Driver class must be used:

class DriverMain{

public static void main(String args[]){

GW4_P4 gw4P4 = new GW4_P4();

int[] array = gw4P4.getArray();

gw4P4.pushZero(array);

//Print the result array

for(int i=0;i

System.out.print(array[i]+" ");

}

}

}

This is the given class code:

class GW4_P4{ public int[] getArray(){ Scanner scanner = new Scanner(System.in); //write your code to get the array and return it } public void pushZero(int array[]){ // write your code } }

Also please create a UML diagram describing all the methods within the class!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!