Python Bubble Sort using Array Module

By | March 20, 2020

Python Bubble Sort using Array Module

# Write a Python program
# to input n numbers in
# Python array and sort them using
# bubble sort
# Perfect Python Programming Tutorials
# Author : (c)

import array
def bubbleSort(arr):
    n = len(arr)
    for i in range(n):
        for j in range(0, n-i-1):
            if arr[j] > arr[j+1] :
                arr[j], arr[j+1] = arr[j+1], arr[j]

# main
# Define array of integer numbers
a = array.array('i', [])

n = int(input('Enter  size of Array='))
# input n numbers in arry
for i in range(n):
    item= int(input("Enter number in array:"))

# call bubbleSort() function for sorting array

# print sorted array
print ("Sorted array is:")
for i in a:
    print (i, '\t')


  Enter  size of Array=5
Enter number in array:67
Enter number in array:345
Enter number in array:6
Enter number in array:-1
Enter number in array:916
Sorted array is:

 976 total views,  2 views today

Leave a Reply

Your email address will not be published.