annotate bubblesort/bubblesort-recursive.py @ 21:7f02682ff5ed

bing4desktop-0.240207-4
author prymula <prymula76@outlook.com>
date Wed, 07 Feb 2024 22:51:58 +0100
parents dcd610585610
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
prymula <prymula76@outlook.com>
parents:
diff changeset
1 #!/usr/bin/env python3
prymula <prymula76@outlook.com>
parents:
diff changeset
2
prymula <prymula76@outlook.com>
parents:
diff changeset
3 tab = [3, 10, 1, 4, 5, 9, 8, 20, 11, 15, 12, 17, 18]
prymula <prymula76@outlook.com>
parents:
diff changeset
4
prymula <prymula76@outlook.com>
parents:
diff changeset
5 def func1(i):
prymula <prymula76@outlook.com>
parents:
diff changeset
6 if i == 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
7 return
prymula <prymula76@outlook.com>
parents:
diff changeset
8 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
9 func2(len(tab) - i - 1)
prymula <prymula76@outlook.com>
parents:
diff changeset
10 #print("i: "+str(i))
prymula <prymula76@outlook.com>
parents:
diff changeset
11 func1(i - 1)
prymula <prymula76@outlook.com>
parents:
diff changeset
12
prymula <prymula76@outlook.com>
parents:
diff changeset
13 def func2(j):
prymula <prymula76@outlook.com>
parents:
diff changeset
14 if j < 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
15 return
prymula <prymula76@outlook.com>
parents:
diff changeset
16 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
17 if (tab[j] > tab[j + 1]):
prymula <prymula76@outlook.com>
parents:
diff changeset
18 tab[j], tab[j+ 1] = tab[j + 1], tab[j]
prymula <prymula76@outlook.com>
parents:
diff changeset
19 #print ("j:"+str(j))
prymula <prymula76@outlook.com>
parents:
diff changeset
20 func2(j - 1)
prymula <prymula76@outlook.com>
parents:
diff changeset
21
prymula <prymula76@outlook.com>
parents:
diff changeset
22 func1(len(tab))
prymula <prymula76@outlook.com>
parents:
diff changeset
23 print(tab)