Sorting algorithms/Insertion sort: Difference between revisions

Added the implementation for Dart. This was translated from the Java version of the algorithm
(Added solution for Action!)
(Added the implementation for Dart. This was translated from the Java version of the algorithm)
Line 1,471:
<pre>arr1 sorted: [2, 4, 11, 17, 19, 24, 25, 28, 44, 46]
arr2 sorted: [2, 4, 11, 17, 19, 24, 25, 28, 44, 46]</pre>
 
=={{header|Dart}}==
 
{{trans|Java}}
 
<lang dart>
 
insertSort(List<int> array){
for(int i = 1; i < array.length; i++){
int value = array[i];
int j = i - 1;
while(j >= 0 && array[j] > value){
array[j + 1] = array[j];
j = j - 1;
}
array[j + 1] = value;
}
return array;
}
 
void main() {
List<int> a = insertSort([10, 3, 11, 15, 19, 1]);
print('${a}');
}
</lang>
{{out}}
<pre>array unsorted: [10, 3, 11, 15, 19, 1];
a sorted: [1, 3, 10, 11, 15, 19]</pre>
 
=={{header|Delphi}}==
Anonymous user