Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1161 from leonardogonfiantini/add-go-reverse-array
Browse files Browse the repository at this point in the history
chore(Go): Add reverse array
  • Loading branch information
ayo-ajayi authored Jun 9, 2023
2 parents af47764 + a4edbaf commit d3c2184
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions algorithms/Go/arrays/reverse-array.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//Description : This program reverses array elements by swapping the first half part of the array
//Time Complexity : O(n/2), where n is the array size
//Auxiliary Space : O(1)

package arrays

import ("fmt")

func ReverseArray(arr []int) {
// get the length of the array
n := len(arr)
// iterate over half of the array and swap corresponding elements
for i := 0; i < n/2; i++ {
arr[i], arr[n-i-1] = arr[n-i-1], arr[i]
}
// print the reversed array
fmt.Println(arr)
}

0 comments on commit d3c2184

Please sign in to comment.