Practice
Bubble Sort a List of Item Names
2024/Oct/Nov·Variant 2
MEDIUMAlgorithms
Array ItemList holds 5 item names as strings. Write procedure BubbleSort() that sorts ItemList into alphabetical order using the bubble sort algorithm.
Input: 5 item names. Output: The names in alphabetical order, one per line.
Example:
Input: Pen
Eraser
Ruler
Book
Marker
Output: Book
Eraser
Marker
Pen
Ruler
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Five names, mixed order
Inputs: Pen, Eraser, Ruler, Book, Marker
Expected: Book
Eraser
Marker
Pen
Ruler
Test 2: Already alphabetical
Inputs: Apple, Banana, Cherry, Date, Fig
Expected: Apple
Banana
Cherry
Date
Fig