Created
November 14, 2018 09:14
-
-
Save CSaratakij/84eaa1c6a73c7955fa62225b8f71d170 to your computer and use it in GitHub Desktop.
Reverse array
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
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