Bubble Sort Algorithm
📖 Scenario: You are helping a librarian organize a small shelf of books by their ID numbers. The books are currently in a random order, and you want to arrange them from the smallest ID to the largest using a simple sorting method.
🎯 Goal: Build a program that sorts a list of book IDs using the Bubble Sort algorithm. You will create the list, set up a variable to track the number of passes, implement the sorting logic, and finally print the sorted list.
📋 What You'll Learn
Create a slice of integers called
bookIDs with the exact values: 34, 12, 25, 9, 56Create an integer variable called
n that stores the length of bookIDsUse nested
for loops with variables i and j to implement the Bubble Sort algorithmSwap adjacent elements in
bookIDs if they are in the wrong orderPrint the sorted
bookIDs slice💡 Why This Matters
🌍 Real World
Sorting is a common task in organizing data, like arranging books, files, or records in order.
💼 Career
Understanding sorting algorithms like Bubble Sort helps in optimizing data processing and is a foundation for learning more advanced algorithms.
Progress0 / 4 steps