nodes: 0, module; 1, function_definition; 2, function_name:shellsort; 3, parameters; 4, block; 5, identifier:inlist; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, comment:# integer division needed; 12, while_statement; 13, comment:# svec is now sorted inlist, and ivec has the order svec[i] = vec[ivec[i]]; 14, return_statement; 15, comment:"""
  Shellsort algorithm.  Sorts a 1D-list.
  
  Usage:   lshellsort(inlist)
  Returns: sorted-inlist, sorting-index-vector (for original list)
  """; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, comparison_operator:gap > 0; 21, block; 22, expression_list; 23, identifier:n; 24, call; 25, identifier:svec; 26, call; 27, identifier:ivec; 28, call; 29, identifier:gap; 30, binary_operator:n / 2; 31, identifier:gap; 32, integer:0; 33, for_statement; 34, expression_statement; 35, comment:# integer division needed; 36, identifier:svec; 37, identifier:ivec; 38, identifier:len; 39, argument_list; 40, attribute; 41, argument_list; 42, identifier:range; 43, argument_list; 44, identifier:n; 45, integer:2; 46, identifier:i; 47, call; 48, block; 49, assignment; 50, identifier:inlist; 51, identifier:copy; 52, identifier:deepcopy; 53, identifier:inlist; 54, identifier:n; 55, identifier:range; 56, argument_list; 57, for_statement; 58, identifier:gap; 59, binary_operator:gap / 2; 60, identifier:gap; 61, identifier:n; 62, identifier:j; 63, call; 64, block; 65, identifier:gap; 66, integer:2; 67, identifier:range; 68, argument_list; 69, while_statement; 70, binary_operator:i - gap; 71, unary_operator; 72, unary_operator; 73, boolean_operator; 74, block; 75, identifier:i; 76, identifier:gap; 77, integer:1; 78, identifier:gap; 79, comparison_operator:j >= 0; 80, comparison_operator:svec[j] > svec[j + gap]; 81, expression_statement; 82, expression_statement; 83, expression_statement; 84, expression_statement; 85, expression_statement; 86, expression_statement; 87, identifier:j; 88, integer:0; 89, subscript; 90, subscript; 91, assignment; 92, assignment; 93, assignment; 94, assignment; 95, assignment; 96, assignment; 97, identifier:svec; 98, identifier:j; 99, identifier:svec; 100, binary_operator:j + gap; 101, identifier:temp; 102, subscript; 103, subscript; 104, subscript; 105, subscript; 106, identifier:temp; 107, identifier:itemp; 108, subscript; 109, subscript; 110, subscript; 111, subscript; 112, identifier:itemp; 113, identifier:j; 114, identifier:gap; 115, identifier:svec; 116, identifier:j; 117, identifier:svec; 118, identifier:j; 119, identifier:svec; 120, binary_operator:j + gap; 121, identifier:svec; 122, binary_operator:j + gap; 123, identifier:ivec; 124, identifier:j; 125, identifier:ivec; 126, identifier:j; 127, identifier:ivec; 128, binary_operator:j + gap; 129, identifier:ivec; 130, binary_operator:j + gap; 131, identifier:j; 132, identifier:gap; 133, identifier:j; 134, identifier:gap; 135, identifier:j; 136, identifier:gap; 137, identifier:j; 138, identifier:gap
code: def shellsort(inlist):
      """
  Shellsort algorithm.  Sorts a 1D-list.
  
  Usage:   lshellsort(inlist)
  Returns: sorted-inlist, sorting-index-vector (for original list)
  """
      n = len(inlist)
      svec = copy.deepcopy(inlist)
      ivec = range(n)
      gap = n / 2   # integer division needed
      while gap > 0:
          for i in range(gap, n):
              for j in range(i - gap, -1, -gap):
                  while j >= 0 and svec[j] > svec[j + gap]:
                      temp = svec[j]
                      svec[j] = svec[j + gap]
                      svec[j + gap] = temp
                      itemp = ivec[j]
                      ivec[j] = ivec[j + gap]
                      ivec[j + gap] = itemp
          gap = gap / 2  # integer division needed
      # svec is now sorted inlist, and ivec has the order svec[i] = vec[ivec[i]]
      return svec, ivec