Skip to content

Commit

Permalink
Merge pull request #1 from ei3kf/PRTest
Browse files Browse the repository at this point in the history
Refactoring to test sonarcloud PR
  • Loading branch information
ei3kf committed Sep 5, 2023
2 parents f1b35a4 + 338f303 commit 5e2a2a7
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions bubblesort.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
def bubblesort(a):
for n in range(len(a)-1,0,-1):
#!/usr/bin/env python3

class BubbleSort:
def __init__(self, arr):
self.arr = arr

def sort(self):
n = len(self.arr)
for i in range(n):
if a[i]>a[i+1]:
scratch = a[i]
a[i] = a[i+1]
a[i+1] = scratch

a = [3,1,5,2,9,6,8,4,7,10]
print(a)
bubblesort(a)
print(a)
swapped = False

for j in range(0, n - i - 1):
if self.arr[j] > self.arr[j + 1]:
self.arr[j], self.arr[j + 1] = self.arr[j + 1], self.arr[j]
swapped = True

if not swapped:
break

def display(self):
for element in self.arr:
print(element, end=" ")
print()


if __name__ == "__main__":
input_array = [64, 34, 25, 12, 22, 11, 90, 128]
bubble_sort = BubbleSort(input_array)
print("Original Array:")
bubble_sort.display()

bubble_sort.sort()

print("Sorted Array:")
bubble_sort.display()


0 comments on commit 5e2a2a7

Please sign in to comment.