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
Has replaced the need for landline telephones in many instance​
Vladimir79 [104]

Explanation:

million landlines. During this same time the number of mobile phone lines that have been subscribed to has ...

Characteristics

7 0
3 years ago
The entirety of a packet at one Layer becoming the payload section at another is know as?
MA_775_DIABLO [31]
The answer to the question is: encapsulation
8 0
2 years ago
Read 2 more answers
AYYOOOO CAN YOU HELP A GIRL OUUTT???
goblinko [34]

Answer: The answer is true

8 0
2 years ago
If an internet document identifies its author but says nothing about her or his qualifications, your textbook recommends that yo
PSYCHO15rus [73]

If the internet document identifies the author, the textbook recommends that you type the author's name into the internet search box.

<h3>What is an internet document?</h3>

These are those documents that are gotten from the a search on the internet. To cite such items there are certain guidelines that are to be followed.

A simple search on a search engine would show you the most important details that this author possesses.

Read more on internet documents here:

brainly.com/question/14715750

5 0
2 years ago
...............................
Gemiola [76]

............................

Mark me brainliest^^

7 0
2 years ago
Read 2 more answers
Other questions:
  • Five computers are connected to a switch in a star topology. what type of network is this?
    12·1 answer
  • In project integration management, project ______ and _______ are intertwined and inseparable activities
    14·1 answer
  • What statement best decribes the relashionship bewteen science and technoligy?
    11·2 answers
  • When a bank account pays compound interest, it pays interest not only on the principal amount that was deposited into the accoun
    15·1 answer
  • Fact Pattern: A sales transaction record designed to contain the information presented below. Column Information 1-10 Customer a
    13·1 answer
  • What is problem scoping
    14·1 answer
  • What is a trojan horse
    8·2 answers
  • File names should be limited to 144 characters.<br><br> true or false
    12·1 answer
  • A network of computers that provides access to information on the web.
    15·2 answers
  • when I turn on my pc using a graphics card, it does give video, and everything is normal, but when I try to turn on my pc with t
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!