-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithms.py
More file actions
54 lines (47 loc) · 1.4 KB
/
algorithms.py
File metadata and controls
54 lines (47 loc) · 1.4 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
t = [4, 5, 6, 2, 22, 46, 34, 78, 9, 10]
# def find_max(array):
# x = 0
# i = array[0]
# for i in range(len(array)):
# if x < array[i]:
# x = array[i]
# return x
#
# print(find_max(t))
#
#
# for counter in range(len(t)):
# for i in range(len(t)-1):
# if t[i] > t[i+1]:
# temp = t[i]
# t[i] = t[i+1]
# t[i+1] = temp
# print(t)
# def bubble_sort(array):
# for counter in range(len(array)):
# for iterator in range(len(array) - 1):
# if array[iterator] > array[iterator + 1]:
# temp = array[iterator]
# array[iterator] = array[iterator + 1]
# array[iterator + 1] = temp
# return array
#
# print(bubble_sort([1,2,56,8,33]))
#
# element = 22
# for i in range(len(t)-1):
# if t[i] == element:
# print(i)
def find_second_max(array):
max_element = array[0]
second_max_element = array[0]
i = array[0]
for i in range(len(array)):
if max_element < array[i]:
second_max_element = max_element
max_element = array[i]
elif second_max_element < array[i] < max_element:
second_max_element = array[i]
print("step " + str(i) + " max_element: " + str(max_element)+ " second_max_element: " +str(second_max_element))
return second_max_element
print(find_second_max([98, 100, 99, 2, 45, 101, 105, 104]))