From e18b27f43ac23689822d4aaaaa3e8d550e41017a Mon Sep 17 00:00:00 2001 From: Shinya Sato Date: Mon, 30 May 2022 20:36:38 +0900 Subject: v0.8.2-2 --- comparison/Python/bsort-20000.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 comparison/Python/bsort-20000.py (limited to 'comparison/Python/bsort-20000.py') diff --git a/comparison/Python/bsort-20000.py b/comparison/Python/bsort-20000.py new file mode 100644 index 0000000..22cc8a7 --- /dev/null +++ b/comparison/Python/bsort-20000.py @@ -0,0 +1,31 @@ +# http://www.geekviewpoint.com/python/sorting/bubblesort +import random + +def bubblesort(A): + for i in range(len(A)): + for k in range(len(A)-1, i, -1): + if (A[k] < A[k-1]): + tmp = A[k] + A[k] = A[k-1] + A[k-1] = tmp + + +def mkRandList(n): + a=[] + for i in range(1,n+1): + a.insert(0, random.randint(0,10000)) + return a + + +def validation(alist): + for i in range(len(alist)-1): + if (alist[i] > alist[i+1]): + return False + + return True + + + +a=mkRandList(20000) +bubblesort(a) +print(validation(a)) -- cgit v1.2.3