Created
December 15, 2022 23:18
-
-
Save abdulrahmanAlotaibi/303f2936be79af800908268fdc44c9df to your computer and use it in GitHub Desktop.
Arrays #2 : Even numbers should appear first than odd numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func evenOdd(nums []int){ | |
for i, j := 0 , len(nums) - 1 ; i <= j;{ | |
if(nums[i] % 2 != 0 && nums[j] % 2 == 0){ // Even | |
nums[i], nums[j] = nums[j],nums[i] | |
} | |
if nums[i] % 2 == 0 { | |
i++ | |
} | |
if nums[j] % 2 != 0 { | |
j-- | |
} | |
} | |
fmt.Println(nums) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment