0

An array a [ 2,3,4,1,4,0,4,5,3,3,1,0,590,32,45 1,0] . I want to make small arrays out of this.

from array a I want to copy the elements into another array (say b) , until 0 is encountered. and then again continuing from the previous 0 found until next 0 comes the elements must get stored in another array say c, so how implement this ? the output should be. b [2,3,4,1,4] c [4,5,3,3,1] d [590,32,45,1]

4th Dec 2016, 6:10 AM
sapan patel
5 Answers
+ 1
You can do it this way: currentArray = 0; for(int i =0; i < mainArray.length;i++) { if (currentArray == 0){ if(mainArray[i]==0) currentArray++; else b.push(mainArray[i]); } if (currentArray == 1){ if(mainArray[i]==0) currentArray++; else c.push(mainArray[i]); } if (currentArray == 2){ if(mainArray[i]==0) currentArray++; else c.push(mainArray[i]); } }
4th Dec 2016, 6:18 AM
Nahuel
Nahuel - avatar
+ 1
@Nahuel Ovejero Awesome bro.!!! But many mistakes in the python code. The list: ---The syntax for 'for loop' is not right for python.Its as follows: for i in mainArray: ---No curly braces and semi-colons throughout the code. ---In last if..else part its 'd.push(mainArray[i])' and not 'c.push(mainArray[i]'. Check Out.!!!
4th Dec 2016, 7:07 AM
MUTYALA SUBBARAYUDU
MUTYALA SUBBARAYUDU - avatar
+ 1
@MUTYALA SUBBARYUDU indeed, I was mistaken, thought it was C++ , but it was phyton!
4th Dec 2016, 7:11 AM
Nahuel
Nahuel - avatar
0
thank you!
4th Dec 2016, 6:46 AM
sapan patel
0
@MUTYALA SUBBARYUDU so in python does push array.push () work???? or should I use list.append for python?
4th Dec 2016, 7:13 AM
sapan patel