Skip to content

Instantly share code, notes, and snippets.

@abdulrahmanAlotaibi
Created December 15, 2022 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdulrahmanAlotaibi/303f2936be79af800908268fdc44c9df to your computer and use it in GitHub Desktop.
Save abdulrahmanAlotaibi/303f2936be79af800908268fdc44c9df to your computer and use it in GitHub Desktop.
Arrays #2 : Even numbers should appear first than odd numbers
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