Question: Sorting Algorithm Simulation Program: - Write a program in Python that simulates the Merge Sort Algorithm. Please incorporate sound effects for swaps. - The program
Sorting Algorithm Simulation Program:
Write a program in Python that simulates the Merge
Sort Algorithm. Please incorporate sound effects for swaps.
The program must accept an array of n numbers, then execute the sort algorithm and print out each step.
i have this code so far but not to sure if it fits the criteria of accepting an array of any n numbers?
import winsound
import os
def mergesortarr depth:
if lenarr:
mid lenarr
L arr:mid
R arrmid:
mergesortL depth
mergesortR depth
i j k
while i lenL and j lenR:
if Li Rj:
arrk Li
i
else:
arrk Rj
j
k
winsound.Beep # Sound effect for swap
printfDepth depth: arr
while i lenL:
arrk Li
i
k
winsound.Beep # Sound effect for swap
printfDepth depth: arr
while j lenR:
arrk Rj
j
k
winsound.Beep # Sound effect for swap
printfDepth depth: arr
if namemain:
arr
printfOriginal array: arr
mergesortarr
printfSorted array: arr
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
