At Westonci.ca, we connect you with the best answers from a community of experienced and knowledgeable individuals. Get detailed answers to your questions from a community of experts dedicated to providing accurate information. Our platform offers a seamless experience for finding reliable answers from a network of knowledgeable professionals.
Sagot :
Answer:
The algorithm is as follows:
0. Start
1. MyArray = []
2. Input n
3. if n <1 or n > 20:
3.1print("Invalid Size")
4. else:
4.1 for [tex]i = 0[/tex] to n - 1:
4.1.1 Input MyArray[i]
4.2 even = []; odd = []
4.3 enum = 0; onum = 0
4.4 for i = 0 to n - 1:
4.4.1 if i%2 == 0:
4.4.1.1 even[enum]=list[i]
4.4.1.2 enum = enum + 1
4.4.2 else:
4.4.2.1 odd[onum]=list[i]
4.4.2.2 onum= onum + 1
4.5 MyArray.clear()
4.6 enum=0
4.7 while even:
4.7.1 minm = even[0]
4.7.2 for x in even:
4.7.2.1 if x < minm:
4.7.2.1.1 minm = x
4.7.3 MMyArray[enum] = minm
4.7.4 even.remove(minm)
4.7.5 enum = enum + 1
4.8 while odd:
4.8.1 maxm = odd[0]
4.8.2 for x in odd:
4.8.2.1 if x > maxm:
4.8.2.1.1 maxm = x
4.8.3 MMyArray[enum] = maxm
4.8.4 odd.remove(maxm)
4.8.5 enum = enum + 1
4.9 for i = 0 to n - 1:
4.9.1 print MyArray[i]
5. Stop
Explanation:
This starts the algorithm
0. Start
This creates an empty array
1. MyArray = []
This gets input for n (the length of the array)
2. Input n
If n is is less than 1 or greater than 20, then the input is invalid
3. if n <1 or n > 20:
3.1print("Invalid Size")
For valid values of n, we have:
4. else:
The italicized gets input into the array
4.1 for [tex]i = 0[/tex] to n - 1:
4.1.1 Input MyArray[i]
This creates empty arrays for even index and for odd index
4.2 even = []; odd = []
This initializes even index and odd index to 0
4.3 enum = 0; onum = 0
This iterates through the array indices
4.4 for i = 0 to n - 1:
If index is even, add array element to even
4.4.1 if i%2 == 0:
4.4.1.1 even[enum]=list[i]
4.4.1.2 enum = enum + 1
If otherwise, add array element to odd
4.4.2 else:
4.4.2.1 odd[onum]=list[i]
4.4.2.2 onum= onum + 1
Clear elements of MyArray
4.5 MyArray.clear()
Set index to 0
4.6 enum=0
Iterate through the even array
4.7 while even:
Set minimum to the first index
4.7.1 minm = even[0]
Sort the array in ascending order
4.7.2 for x in even:
4.7.2.1 if x < minm:
4.7.2.1.1 minm = x
Add the sorted array into MyArray
4.7.3 MMyArray[enum] = minm
Delete the elements of even array
4.7.4 even.remove(minm)
4.7.5 enum = enum + 1
Iterate through the odd array
4.8 while odd:
Set maximum to the first index
4.8.1 maxm = odd[0]
Sort the array in descending order
4.8.2 for x in odd:
4.8.2.1 if x > maxm:
4.8.2.1.1 maxm = x
Add the sorted array into MyArray
4.8.3 MMyArray[enum] = maxm
Delete the elements of odd array
4.8.4 odd.remove(maxm)
4.8.5 enum = enum + 1
Iterate through the indices of the double sorted MyArray
4.9 for i = 0 to n - 1:
Print each array element
4.9.1 print MyArray[i]
End algorithm
5. Stop
See attachment for the program implemented in Python
Thanks for using our service. We aim to provide the most accurate answers for all your queries. Visit us again for more insights. We hope this was helpful. Please come back whenever you need more information or answers to your queries. Get the answers you need at Westonci.ca. Stay informed with our latest expert advice.