Skip to content

Instantly share code, notes, and snippets.

@OnlyTarg
Last active October 10, 2022 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OnlyTarg/2aa922bf1e25992c675d2e51daaa828c to your computer and use it in GitHub Desktop.
Save OnlyTarg/2aa922bf1e25992c675d2e51daaa828c to your computer and use it in GitHub Desktop.
//сортировка вставками
void main() {
final array = <int>[5, 2, 6, 14, 87, 11, 9, 3, 76];
print(array);
sort(array);
print(array);
}
List<int> sort(List<int> array) {
//main for loop
for (int mainIndex = 0; mainIndex < array.length; mainIndex++) {
int value = array[mainIndex];
//secondary for loop for sorting values
int i = mainIndex - 1;
for (; i >= 0; i--) {
if (value > array[i]) break;
array[i + 1] = array[i];
}
array[i + 1] = value;
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment