日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

剑指offer之 调整奇数偶数数组位置

發布時間:2025/3/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 剑指offer之 调整奇数偶数数组位置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package Problem14;/** 問題描述:* 輸入一個整數數組,實現一個函數來調整該數組中數字的順序,使得所有奇數位與數組的前半部分,所有偶數位與數組的* 后半部分*/ public class ReorderOddEven {public static void reOrder(int array[]) {int firstIndex = 0;int lastIndex = array.length - 1;if (array == null || (0 == array.length)) {return;}while (firstIndex < lastIndex) {while ((firstIndex < lastIndex) && !(isEven(array[firstIndex]))) {firstIndex++;}while ((firstIndex < lastIndex) && isEven(array[lastIndex])) {lastIndex--;}if (firstIndex < lastIndex) {int temp = array[firstIndex];array[firstIndex] = array[lastIndex];array[lastIndex] = temp;}}}// 進行解耦操作:odd(奇數)、even(偶數)private static boolean isEven(int n) {return (n & 1) == 0;}public static void printArr(int array[]) {for (int i = 0; i < array.length; i++) {System.out.print(array[i] + "");}}

  

轉載于:https://www.cnblogs.com/toov5/p/7656977.html

總結

以上是生活随笔為你收集整理的剑指offer之 调整奇数偶数数组位置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。