Oct 152013
 

Given an array containing both positive and negative integers, write code to rearrange the elements so that positive and negative numbers comes alternately. If positive (or negative) integers is not equal in number then extra positive (or negative) numbers should come at the end of array. For example:

Input : {1, 2, -2, -5, 6, 7, -8}
Output: {1, -2, 2, -5, 6, -8, 7}

Input : {-1, 2, 3, -5, -6, -7, -8}
Output: {-1, 2, -5, 3, -6, -7, -8}

Continue reading »

vliegen123.nl