Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. main() {
  2. print(insertionSort([8,9, 4, 2, 6,10,12]));
  3. }
  4.  
  5. List<int> insertionSort(List<int> list) {
  6. for (int j = 1; j < list.length; j++) {
  7. int key = list[j];
  8.  
  9. int i = j - 1;
  10.  
  11. while (i >= 0 && list[i] > key) {
  12. list[i + 1] = list[i];
  13. i = i - 1;
  14. list[i + 1] = key;
  15. }
  16. }
  17. return list;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement