Skip to content

Instantly share code, notes, and snippets.

@CSaratakij
Created November 14, 2018 09:14
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 CSaratakij/84eaa1c6a73c7955fa62225b8f71d170 to your computer and use it in GitHub Desktop.
Save CSaratakij/84eaa1c6a73c7955fa62225b8f71d170 to your computer and use it in GitHub Desktop.
Reverse array
def main():
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print("Before reverse : ")
print(numbers)
numbers = reverse_array(numbers)
print("")
print("After reverse : ")
print(numbers)
def reverse_array(list):
minIndex = 0
maxIndex = len(list) - 1
while (maxIndex > minIndex):
list[minIndex], list[maxIndex] = list[maxIndex], list[minIndex]
minIndex += 1
maxIndex -= 1
return list
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment