Computer Science, asked by khanrizaan, 8 months ago

Q12. Write a program to sort the following array elements using Bubble sort technique. [10] For Example: INPUT-> 25 26 87 41 20 25 24 26 OUTPUT -> 20 24 25 25 26 26 41 87

Answers

Answered by gaganadithyareddy9
1

Answer:

Hey! Buddy this code works only in python.

# SORTING ARRAY IN ASCENDING ORDER USING BUBBLE SORT

arr = [5, 2, 8, 1, 9]

temp = 0

print('Elements of original array: ')

print(len(arr))

print("_________")

for i in range(0, len(arr)):

print(arr[i], end = ' ')

for i in range(0, len(arr)):

for j in range(i+1, len(arr)):

if arr[i]>arr[j]:

temp = arr[i]

arr[i] = arr[j]

arr[j] = temp

print(' ')

print("Elements of array sorted in ascending order: ")

for i in range(0, len(arr)):

print(arr[i], end = ' ')

Hope it helps!!

Similar questions