Given an array of integers, you need to segregate odd and even numbers in an array.
Please note: Order of elements can be changed.
- Algorithm
- Let's say array is arr[]
- Initialise two index variable , left=0 and right=arr.length-1
- Increment left variable until you get odd number
- Decrement right variable until you get even number.
- If left < right, swap arr[left] and arr[right]
- In the end, you will see that you have even numbers on left side and odd numbers on right side.
Java code to separate odd and even numbers in an array
when you run the above program, you will get the below output:
Don't miss the next article! 
Be the first to be notified when a new article or Kubernetes experiment is published.                            
Share This

 
 
