aboutsummaryrefslogtreecommitdiff
path: root/comparison/Python
diff options
context:
space:
mode:
Diffstat (limited to 'comparison/Python')
-rw-r--r--comparison/Python/Makefile2
-rw-r--r--comparison/Python/bsort-20000.py31
-rw-r--r--comparison/Python/isort-20000.py31
3 files changed, 63 insertions, 1 deletions
diff --git a/comparison/Python/Makefile b/comparison/Python/Makefile
index 21f4b3d..c77d677 100644
--- a/comparison/Python/Makefile
+++ b/comparison/Python/Makefile
@@ -1,5 +1,5 @@
COMMAND = python3
-TARGET = dummy.py ack3-11.py fib38.py bsort-40000.py isort-40000.py qsort-260000.py msort-260000.py
+TARGET = dummy.py ack3-11.py fib38.py bsort-20000.py isort-20000.py qsort-260000.py msort-260000.py
BENCHMARK = bash ../tools/sptest_scripts.sh
LOG = log.txt
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))
diff --git a/comparison/Python/isort-20000.py b/comparison/Python/isort-20000.py
new file mode 100644
index 0000000..b37fe5d
--- /dev/null
+++ b/comparison/Python/isort-20000.py
@@ -0,0 +1,31 @@
+import random
+
+def insert_sort(arr):
+ for i in range(1, len(arr)):
+ j = i - 1
+ ele = arr[i]
+ while arr[j] > ele and j >= 0:
+ arr[j + 1] = arr[j]
+ j -= 1
+ arr[j + 1] = ele
+ return arr
+
+
+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)
+insert_sort(a)
+print(validation(a))