Welcome to Westonci.ca, where you can find answers to all your questions from a community of experienced professionals. Experience the ease of finding reliable answers to your questions from a vast community of knowledgeable experts. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.

Write a function that receives a StaticArray where the elements are in sorted order, and returns a new StaticArray with squares of the values from the original array, sorted in non-descending order. The original array should not be modified.

Sagot :

Answer:

def sa_sort(arr):

   for i in range(len(arr)):

       for j in range(0, len(arr) - i-1):

           if arr[j] > arr[j + 1]:

               arr[j], arr[j + 1] = arr[j + 1], arr[j]

test_cases = (

   [1, 10, 2, 20, 3, 30, 4, 40, 5], ['zebra2', 'apple', 'tomato', 'apple', 'zebra1'],

   [(1, 1), (20, 1), (1, 20), (2, 20)])

for case in test_cases:

   print(case)

   sa_sort(case)

   print(case)

Explanation:

We appreciate your visit. Hopefully, the answers you found were beneficial. Don't hesitate to come back for more information. Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. We're here to help at Westonci.ca. Keep visiting for the best answers to your questions.