C++将整数数组分割成奇数和偶数两个数组的代码
//get an array and by using it, create two different array which are odd and even void arraySplitter(int *&array, int size, int &sizeEven, int &sizeOdd, int *&array2) { int even = 0; int odd = 0; //determine how many member of given array is even and how many of them is odd for (int i = 0; i < size; i++) { if(array[i]%2==0) { even++; } else { odd++; } } //by using even and odd parameter, creates two different array //which will be used soon int *arrayOdd= new int[even]; int *arrayEven = new int[odd]; int m = 0; int n = 0; //creates arrays which has only even or odd members for (int i = 0; i < size; i++) { if(array[i]%2==0) { arrayEven[m] = array[i]; m++; } else { arrayOdd[n] = array[i]; n++; } } //returns arrays with pass by referance array = arrayEven; array2 = arrayOdd; }