def insertion_sort(collection):
          for loop_index in range(1, len(collection)):
              insertion_index = loop_index
              while (
                  insertion_index > 0
                  and collection[insertion_index - 1] > collection[insertion_index]
              ):
                  collection[insertion_index], collection[insertion_index - 1] = (
                      collection[insertion_index - 1],
                      collection[insertion_index],
                  )
                  insertion_index -= 1
          return collection
      
      Python language logo

      Insertion Sort

      0

      0

      avatar
      HARIGOVIND VALSAKUMAR
      Python
      InsertionSort
      HGV Public Cookbook

      Function to perform Insertion sort.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.