"""
This is a code example of
sorting an array using Bubble Sort
in Python Programming.
Author: Code2care.org
Date: 03-Apr-2022
Version: 1.0
"""
# The provided Input Array to sort using bubble sort
arr = [30, 20, 10, -20, 40, -40, 70, 60, 90, 80, -50]
def bubble_sort(input_arr):
for i in range(len(arr)-1):
for j in range(0, len(arr)-i-1):
if arr[j] > arr[j + 1] :
arr[j], arr[j + 1] = arr[j + 1], arr[j]
print ("Input Unsorted Array: %d", arr)
bubble_sort(arr)
print ("Bubble Sorted Array : %d", arr)
Output:
Input Unsorted Array: %d [30, 20, 10, -20, 40, -40, 70, 60, 90, 80, -50]
Bubble Sorted Array : %d [-50, -40, -20, 10, 20, 30, 40, 60, 70, 80, 90]

- tkinter - Hello World! Program
- How to install Python Specific version (3.8, 3.9 or 3.10) using Brew
- How to install SpaCy (NLP Library) on Mac
- Python matplotlib segmentation fault: 11 macOS Big Sur
- How to uninstall pip Python packages
- 3 Ways to find if element is present in a List in Python
- How to Convert Python String to DateTime Object
- Python f-strings Formatted String Literals Syntax and Examples
- Where does brew install python in macOS
- Take input argument from command line in Python Programming
- Advanced print() Function Tutorial and Techniques for Python Developers
- How to add borders to tkinter label text
- Whats new in Python 3.10 Pre-release
- Float built-in function in Python
- List of All 35 Reserved Keywords in Python Programming Language 3.11
- How to check if Key Exists in Python Dictionary?
- Read a file line by line in Python Program
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- What is the Max and Minimum Value of int type in Python?
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- Fix: TypeError: can only concatenate str (not int) to str in Python
- How to take user input from the console in a Python program
- [Fix] TypeError: str object is not callable in Python
- 3 Python program to add two numbers
- How to delete a file using Python code example
- Change Title text for Android Activity using java code - Android
- How to make a div tag clickable - Html
- Skip Test Maven while creating package command - Java
- Windows 10 now has a new enhanced Calculator with a new icon - News
- SharePoint Server 2016 error Microsoft Office Online Server 2016 cant be installed on the same machine as a Microsoft SharePoint Server product - SharePoint
- How to make macOS Terminal window Transparent (or Opaque) - MacOS
- Check SSH/OpenSSH version Command - Linux
- List of All Apple Silicon ARM Based M1/M2 Mac [updated Oct 2022) - MacOS