output the odds keeping their original order in the input array, and then output the evens also maintain the original order. Each number is output in one line
时间: 2024-02-22 16:55:11 浏览: 18
Sure, I can help you with that. Here's the Python code to achieve that:
```python
# Input array
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# Initialize two empty lists for odds and evens
odds = []
evens = []
# Iterate through the array and append odd and even numbers to their respective lists
for num in arr:
if num % 2 == 0:
evens.append(num)
else:
odds.append(num)
# Output the odds first, maintaining their original order
for odd in odds:
print(odd)
# Output the evens next, maintaining their original order
for even in evens:
print(even)
```
This code first initializes two empty lists for odds and evens. It then iterates through the input array and appends odd and even numbers to their respective lists. Finally, it outputs the odds first, maintaining their original order, and then outputs the evens, also maintaining their original order.