program to initialize the following five great king of india and display them as ascending order using bubble sort
Answers
Answered by
2
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr
kings = [
"Krishnadevaraya",
"Chandragupta",
"Samudragupta",
"Shivaji",
"Ajatasatru"
]
print(bubble_sort(kings))
Answered by
1
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr
kings = [
"Krishnadevaraya",
"Chandragupta",
"Samudragupta",
"Shivaji",
"Ajatasatru"
]
print(bubble_sort(kings))
Similar questions