# 76. 调整数组顺序使奇数位于偶数前面

java

```java
import utils.ArrayUtils;

/**
 * 调整数组顺序使奇数位于偶数前面
 *
 * 输入一个整数数组，实现一个函数来调整该数组中数字的顺序，
 * 使得所有的奇数位于数组的前半部分，所有的偶数位于位于数组的后半部分，
 * 并保证奇数和奇数，偶数和偶数之间的相对位置不变。
 *
 */
public class ReOrderArraySolution {
    public void reOrderArray(int [] array) {
        int n=array.length;
        int k=0;//已排好的奇数位置
        for(int i=0;i<n;i++){
            if(array[i]%2==1){
                int j=i;
                while (j>k){
                    int tmp=array[j];
                    array[j]=array[j-1];
                    array[j-1]=tmp;
                    j--;
                }
                k++;
            }
        }
    }

    public static void main(String[] args){
        //output:1,3,5,7,2,4,6
        int[] array={
                1,2,3,4,5,6,7
        };
        new ReOrderArraySolution().reOrderArray(array);
        ArrayUtils.printArray(array);
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/shua-ti/shu-ju-jie-gou-lei/76-tiao-zheng-shu-zu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
