1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
klio [65]
1 year ago
11

c g given an array, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero eleme

nts
Computers and Technology
1 answer:
o-na [289]1 year ago
6 0

The output for an array of elements [0,1,0,3,12] is  [1,3,12,0,0]

<h3>What is the function to get the desired output?</h3>
  • Let us consider an array of elements,

          Input = [0,1,0,3,12]

  • The function code is given by,

class Solution {

public:

   void moveZeroes(vector<int>& nums) {

       int count=0;

       for(int i=0;i<nums.size();i++)

       {

           if(nums[i]==0)

           {

               nums.erase(nums.begin()+i);

               ++count; //This is to count number of zeroes.

           }

       }

      for(int i = 0 ; i<count ; i ++)

          nums . push_back(0);  //To input zero at the end of the vector count times.      

}

};

The output for an array of elements [0,1,0,3,12] is  [1,3,12,0,0] where all 0's are moved to the end,  while maintaining the relative order of the non-zero elements,

<h3>What is an array?</h3>
  • A collection of items that are either values or variables is referred to as an array in computer science.
  • Each element is identifiable by at least one array index or key.
  • Each element of an array is recorded such that a mathematical formula can be used to determine its position from its index tuple.
  • A linear array, often known as a one-dimensional array, is the simplest sort of data structure.

To learn more about array, refer:

brainly.com/question/19634243

#SPJ4

You might be interested in
What is this please help me ?
Naddika [18.5K]
A OR C is the answer
5 0
2 years ago
Read 2 more answers
Implement a class Rectangle. Provide a constructor to construct a rectangle with a given width and height, member functions get_
Luba_88 [7]

Answer:

Explanation:

The following code is written in Java. It creates the Rectangle class with the height and width variables. The constructor takes these variables as parameters to create Rectangle objects. It creates the get_perimeter method that sums up two of each side in order to get the perimeter of the Rectangle. A get_area method multiplies the height by the width to get the area. Finally, a resize method takes in a double factor variable and multiplies the height and the width by the factor to get a resized Rectangle object.

class Rectangle {

   double height, width;

   public Rectangle(double height, double width) {

       this.height = height;

       this.width = width;

   }

   

   public double get_perimeter() {

       return (this.height + this.height + this.width + this.width);

   }

   

   public double get_area() {

       return (this.height * this.width);

   }

   

   public void resize(double factor) {

       this.height *= factor;

       this.width *= factor;

   }

}

3 0
2 years ago
Privacy concerns, financial information, security of your personal data has
Verdich [7]

Answer:

never share any personal info, always use VPN when on public wifi

7 0
3 years ago
Select all that apply. Purposes of writing include:
nalin [4]
All of these choices are reasons people write. they all appeal to different people
6 0
3 years ago
Read 2 more answers
With what software tool can you see the applications that are currently runni
coldgirl [10]

Answer:

Task Manager

Explanation:

On windows, you can press Ctrl + Esc and it will open Task Manager.

You will see all the currently running programs and the amount of resources they are currently using.

7 0
2 years ago
Other questions:
  • A(n) ____ algorithm is a set of specific, sequential steps that describe in natural language exactly what a computer program mus
    5·1 answer
  • explain the key reasons why entity relationship modeling is important, and determine at least (1) way in which it impacts the ov
    5·1 answer
  • Enzymes_____________.
    7·1 answer
  • What are the best data structures to create the following items? And why?
    13·1 answer
  • I have been charged for brainly plus yet I still have to watch ads why? What do I do?
    12·2 answers
  • Durante 10s, la velocidad de rotación y el momento de giro de las ruedas de un coche eléctrico son 100 rpm y 1405,92 Nm, respect
    13·1 answer
  • Define a function compute_gas_volume that returns the volume of a gas given parameters pressure, temperature, and moles. Use
    12·1 answer
  • Ethernet use a contention-based media access method defined by the IEEE 802.3 standards called ___ .
    9·1 answer
  • Explain ONE negative outcomes of not matching an ICT product to the correct audience:
    15·1 answer
  • The Jacquard Loom used ______________ to change the operation of the loom.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!