Skip to content

Commit 13f07c7

Browse files
Merge pull request raviprakashdev#66 from coderjoker666/master
Update Python program
2 parents e28e300 + 0152ceb commit 13f07c7

3 files changed

Lines changed: 28 additions & 15 deletions

File tree

Bubble Sort_2.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

Python program

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
print ("Hello World"
1+
#THIS PROGRAMME PRINT HELLO WORLD
2+
print('Hello,World!')

optimized Bubble Sort.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def bubbleSort(array):
2+
3+
# Run loops two times: one for walking throught the array
4+
# and the other for comparison
5+
for i in range(len(array)):
6+
7+
# swapped keeps track of swapping
8+
swapped = True
9+
for j in range(0, len(array) - i - 1):
10+
11+
# To sort in descending order, change > to < in this line.
12+
if array[j] > array[j + 1]:
13+
14+
# Swap if greater is at the rear position
15+
(array[j], array[j + 1]) = (array[j + 1], array[j])
16+
swapped = False
17+
18+
# If there is not swapping in the last swap, then the array is already sorted.
19+
if swapped:
20+
break
21+
22+
23+
data = [-2, 45, 0, 11, -9]
24+
bubbleSort(data)
25+
print('Sorted Array in Ascending Order:')
26+
print(data)

0 commit comments

Comments
 (0)