-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py~
More file actions
35 lines (25 loc) · 799 Bytes
/
Copy pathmain.py~
File metadata and controls
35 lines (25 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import time
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
dt = 0
def insertionSort(array):
t0 = time.perf_counter()
for x in range(len(array)):
while array[x] < array[x - 1] and x > 0:
temp = array[x]
array[x] = array[x - 1]
array[x - 1] = temp
x = x - 1
dt = time.perf_counter() - t0
plt.rcParams["figure.figsize"] = (12, 8)
plt.rcParams["font.size"] = 16
N = int(input("How many number do you wanna randomize?"))
arr = np.round(1000 * np.random.random_sample(N), 0)
fig, ax = plt.subplots()
ax.bar(range(0, len(arr)), arr, align="edge")
print(f"insertionSort(arr)")
fig, ax = plt.subplots()
ax.bar(range(0, len(arr)), arr, align="edge")
plt.show()