Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
(Added Qi) |
No edit summary |
||
Line 991: | Line 991: | ||
} |
} |
||
}</lang> |
}</lang> |
||
=={{header|NetRexx}}== |
|||
<lang NetRexx>/* NetRexx */ |
|||
options replace format comments java crossref savelog symbols binary |
|||
import java.util.List |
|||
placesList = [String - |
|||
"UK London", "US New York", "US Boston", "US Washington" - |
|||
, "UK Washington", "US Birmingham", "UK Birmingham", "UK Boston" - |
|||
] |
|||
lists = [ - |
|||
placesList - |
|||
, insertionSort(String[] Arrays.copyOf(placesList, placesList.length)) - |
|||
] |
|||
loop ln = 0 to lists.length - 1 |
|||
cl = lists[ln] |
|||
loop ct = 0 to cl.length - 1 |
|||
say cl[ct] |
|||
end ct |
|||
say |
|||
end ln |
|||
return |
|||
method insertionSort(A = String[]) public constant binary returns String[] |
|||
rl = String[A.length] |
|||
al = List insertionSort(Arrays.asList(A)) |
|||
al.toArray(rl) |
|||
return rl |
|||
method insertionSort(A = List) public constant binary returns ArrayList |
|||
loop i_ = 1 to A.size - 1 |
|||
value = A.get(i_) |
|||
j_ = i_ - 1 |
|||
loop label j_ while j_ >= 0 |
|||
if (Comparable A.get(j_)).compareTo(Comparable value) <= 0 then leave j_ |
|||
A.set(j_ + 1, A.get(j_)) |
|||
j_ = j_ - 1 |
|||
end j_ |
|||
A.set(j_ + 1, value) |
|||
end i_ |
|||
return ArrayList(A) |
|||
</lang> |
|||
;Output |
|||
<pre> |
|||
UK London |
|||
US New York |
|||
US Boston |
|||
US Washington |
|||
UK Washington |
|||
US Birmingham |
|||
UK Birmingham |
|||
UK Boston |
|||
UK Birmingham |
|||
UK Boston |
|||
UK London |
|||
UK Washington |
|||
US Birmingham |
|||
US Boston |
|||
US New York |
|||
US Washington |
|||
</pre> |
|||
=={{header|Objeck}}== |
=={{header|Objeck}}== |