nodes: 0, module; 1, function_definition; 2, function_name:cocktail_shaker_sort; 3, parameters; 4, block; 5, identifier:arr; 6, expression_statement; 7, function_definition; 8, expression_statement; 9, expression_statement; 10, while_statement; 11, return_statement; 12, comment:"""
      Cocktail_shaker_sort
      Sorting a given array
      mutation of bubble sort
  
      reference: https://en.wikipedia.org/wiki/Cocktail_shaker_sort
      
      Worst-case performance: O(N^2)
      """; 13, function_name:swap; 14, parameters; 15, block; 16, assignment; 17, assignment; 18, identifier:swapped; 19, block; 20, identifier:arr; 21, identifier:i; 22, identifier:j; 23, expression_statement; 24, identifier:n; 25, call; 26, identifier:swapped; 27, True; 28, expression_statement; 29, for_statement; 30, if_statement; 31, expression_statement; 32, for_statement; 33, assignment; 34, identifier:len; 35, argument_list; 36, assignment; 37, identifier:i; 38, call; 39, block; 40, comparison_operator:swapped == False; 41, block; 42, assignment; 43, identifier:i; 44, call; 45, block; 46, pattern_list; 47, expression_list; 48, identifier:arr; 49, identifier:swapped; 50, False; 51, identifier:range; 52, argument_list; 53, if_statement; 54, identifier:swapped; 55, False; 56, return_statement; 57, identifier:swapped; 58, False; 59, identifier:range; 60, argument_list; 61, if_statement; 62, subscript; 63, subscript; 64, subscript; 65, subscript; 66, integer:1; 67, identifier:n; 68, comparison_operator:arr[i - 1] > arr[i]; 69, block; 70, identifier:arr; 71, binary_operator:n-1; 72, integer:0; 73, unary_operator; 74, comparison_operator:arr[i - 1] > arr[i]; 75, block; 76, identifier:arr; 77, identifier:i; 78, identifier:arr; 79, identifier:j; 80, identifier:arr; 81, identifier:j; 82, identifier:arr; 83, identifier:i; 84, subscript; 85, subscript; 86, expression_statement; 87, expression_statement; 88, identifier:n; 89, integer:1; 90, integer:1; 91, subscript; 92, subscript; 93, expression_statement; 94, expression_statement; 95, identifier:arr; 96, binary_operator:i - 1; 97, identifier:arr; 98, identifier:i; 99, call; 100, assignment; 101, identifier:arr; 102, binary_operator:i - 1; 103, identifier:arr; 104, identifier:i; 105, call; 106, assignment; 107, identifier:i; 108, integer:1; 109, identifier:swap; 110, argument_list; 111, identifier:swapped; 112, True; 113, identifier:i; 114, integer:1; 115, identifier:swap; 116, argument_list; 117, identifier:swapped; 118, True; 119, binary_operator:i - 1; 120, identifier:i; 121, binary_operator:i - 1; 122, identifier:i; 123, identifier:i; 124, integer:1; 125, identifier:i; 126, integer:1
code: def cocktail_shaker_sort(arr):
      """
      Cocktail_shaker_sort
      Sorting a given array
      mutation of bubble sort
  
      reference: https://en.wikipedia.org/wiki/Cocktail_shaker_sort
      
      Worst-case performance: O(N^2)
      """
  
      def swap(i, j):
          arr[i], arr[j] = arr[j], arr[i]
  
      n = len(arr)
      swapped = True
      while swapped:
          swapped = False
          for i in range(1, n):
              if arr[i - 1] > arr[i]:
                  swap(i - 1, i)
                  swapped = True
          if swapped == False:
              return arr
          swapped = False
          for i in range(n-1,0,-1):
              if arr[i - 1] > arr[i]:
                  swap(i - 1, i)
                  swapped = True
      return arr