Skip to content
Snippets Groups Projects
Commit 3772f5c8 authored by nilsl99's avatar nilsl99
Browse files

Implemented Aufgabe02 with testing

parent 95e19133
Branches
Tags
No related merge requests found
def find_min_max(A):
curr_min = A[0]
curr_max = A[0]
for i in A[1:]:
if i < curr_min:
curr_min = i
elif i > curr_max:
curr_max = i
return curr_min, curr_max
def find_min_max_recursive(A, l=0, r=None):
if r is None:
r = len(A)
if r - l == 1:
return A[l], A[l]
min1, max1 = find_min_max_recursive(A, l, (l+r)//2)
min2, max2 = find_min_max_recursive(A, (l+r)//2, r)
if min1 < min2:
minA = min1
else:
minA = min2
if max1 > max2:
maxA = max1
else:
maxA = max2
return minA, maxA
%% Cell type:code id: tags:
``` python
import random
from Aufgabe02 import find_min_max, find_min_max_recursive
```
%% Cell type:code id: tags:
``` python
num_list = range(10, 100)
rand_list = random.choices(num_list, k=20)
print(rand_list)
print(min(rand_list), max(rand_list))
print(find_min_max(rand_list))
print(find_min_max_recursive(rand_list))
```
%% Output
[28, 99, 48, 91, 55, 36, 94, 36, 66, 69, 85, 94, 64, 83, 57, 31, 80, 51, 65, 39]
28 99
(28, 99)
(28, 99)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment