issue adding elements to an array
Sorry, this is the right code that shows 'the issue': function static void insert_1( string array[], string x, int pos ) { string mom_arr[0]; if( pos < array.size() && pos >= 0 ) { for( pos => int c; c < array.size(); c++ ) { mom_arr << array[c]; } x => array[ pos ]; array.size( array.size() + 1 ); for( 0 => int c; c < mom_arr.size(); c++ ) { mom_arr[c] => array[ c + pos + 1 ]; } } else if( pos == array.size() ) { array << x; } } function static void insert_2( string array[], string x, int pos ) { string mom_arr[0]; if( pos < array.size() && pos >= 0 ) { for( pos => int c; c < array.size(); c++ ) { mom_arr.size( mom_arr.size() + 1 ); array[c] => mom_arr[ c - pos ]; } x => array[ pos ]; array.size( array.size() + 1 ); for( 0 => int c; c < mom_arr.size(); c++ ) { mom_arr[c] => array[ c + pos + 1 ]; } } else if( pos == array.size() ) { array << x; } } ["a", "b", "c"] @=> string s_1[]; insert_1( s_1, "ONE", 1 ); for( 0 => int c; c < s_1.size(); c++ ) { <<< s_1[c] >>>; } <<< "" >>>; ["a", "b", "c"] @=> string s_2[]; insert_2( s_2, "ONE", 1 ); for( 0 => int c; c < s_2.size(); c++ ) { <<< s_2[c] >>>; }
participants (1)
-
Mario Buoninfante