update meta data
This commit is contained in:
parent
f3a896c724
commit
90e15ed6ce
3307 changed files with 1674 additions and 7 deletions
24
Task/Sorting-algorithms-Gnome-sort/00DESCRIPTION
Normal file
24
Task/Sorting-algorithms-Gnome-sort/00DESCRIPTION
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{{Sorting Algorithm}}
|
||||
{{Wikipedia|Gnome sort}}
|
||||
Gnome sort is a sorting algorithm which is similar to [[Insertion sort]], except that moving an element to its proper place is accomplished by a series of swaps, as in [[Bubble Sort]].
|
||||
|
||||
The pseudocode for the algorithm is:
|
||||
'''function''' ''gnomeSort''(a[0..size-1])
|
||||
i := 1
|
||||
j := 2
|
||||
'''while''' i < size '''do'''
|
||||
'''if''' a[i-1] <= a[i] '''then'''
|
||||
''// for descending sort, use >= for comparison''
|
||||
i := j
|
||||
j := j + 1
|
||||
'''else'''
|
||||
'''swap''' a[i-1] '''and''' a[i]
|
||||
i := i - 1
|
||||
'''if''' i = 0 '''then'''
|
||||
i := j
|
||||
j := j + 1
|
||||
'''endif'''
|
||||
'''endif'''
|
||||
'''done'''
|
||||
|
||||
'''Task''': implement the Gnome sort in your language to sort an array (or list) of numbers.
|
||||
Loading…
Add table
Add a link
Reference in a new issue