mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
Added Whitespace and Docstring (#924)
* Added Whitespace and Docstring I modified the file to make Pylint happier and make the code more readable. * Beautified Code and Added Docstring I modified the file to make Pylint happier and make the code more readable. * Added DOCSTRINGS, Wikipedia link, and whitespace I added DOCSTRINGS and whitespace to make the code more readable and understandable. * Improved Formatting * Wrapped comments * Fixed spelling error for `movement` variable * Added DOCSTRINGs * Improved Formatting * Corrected whitespace to improve readability. * Added docstrings. * Made comments fit inside an 80 column layout.
This commit is contained in:
@ -1,29 +1,31 @@
|
||||
"""Gnome Sort Algorithm."""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
def gnome_sort(unsorted):
|
||||
"""
|
||||
Pure implementation of the gnome sort algorithm in Python.
|
||||
"""
|
||||
"""Pure implementation of the gnome sort algorithm in Python."""
|
||||
if len(unsorted) <= 1:
|
||||
return unsorted
|
||||
|
||||
|
||||
i = 1
|
||||
|
||||
|
||||
while i < len(unsorted):
|
||||
if unsorted[i-1] <= unsorted[i]:
|
||||
if unsorted[i - 1] <= unsorted[i]:
|
||||
i += 1
|
||||
else:
|
||||
unsorted[i-1], unsorted[i] = unsorted[i], unsorted[i-1]
|
||||
unsorted[i - 1], unsorted[i] = unsorted[i], unsorted[i - 1]
|
||||
i -= 1
|
||||
if (i == 0):
|
||||
i = 1
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
raw_input # Python 2
|
||||
except NameError:
|
||||
raw_input = input # Python 3
|
||||
|
||||
|
||||
user_input = raw_input('Enter numbers separated by a comma:\n').strip()
|
||||
unsorted = [int(item) for item in user_input.split(',')]
|
||||
gnome_sort(unsorted)
|
||||
|
Reference in New Issue
Block a user