π The Tournament of the Shifting Blades: The Bubble Sort Legend
"Strength is not proven by standing still.
True warriors find their rightful place in the order of blades."
β Edict of the First King
In the realm of scattered banners, warriors stood shoulder to shoulder, yet no order bound them. A squire might boast before a knight, and a knight before a king. Chaos was written into the very line of steel.
The High King, weary of such disorder, proclaimed the Grand Tournament. Only through duels would the warriors discover their rightful places. With every clash, the strongest would fall back and the weakest rise forward, until the line itself sang of balance.
π The Call to Arms
#include <iostream>
#include <vector>
using namespace std;
The scribes opened their scrolls, and the arena was drawn upon the parchment. The warriors would be kept within a line of steel β the vector
β and their story inked through the streams of the iostream
.
βοΈ The Arena Opens
void bubbleSort(vector<int>& arr) {
The gates of the arena creaked open. Into it, the warriors marched. The ritual was called bubbleSort, and its purpose was as old as the throne itself β to bring order where there was none.
int n = arr.size();
The Herald stepped forward, his voice booming across the stands. He counted every warrior, one by one, until the crowd knew how many would fight. That number, n
, was the measure of destiny.
πΉ The Rounds Begin
for (int i = 0; i < n - 1; i++) {
The first round began. The crowd rose to their feet, for they knew each wave of battle would settle one champion. With every clash, the mightiest of that round would be pushed to the end, where he would stand unmoved again. The next round, therefore, needed fewer tests, for one place had already been claimed.
π‘οΈ The Neighbor Duels
for (int j = 0; j < n - i - 1; j++) {
Within each round, warriors turned to face their neighbors. No swords were drawn from across the line; only the one beside you mattered. Each duel was swift, brutal, and watched by all. In this way, the order was forged step by step, neighbor by neighbor.
βοΈ The Kingβs Judgment
if (arr[j] > arr[j + 1]) {
The King watched closely. If a warrior stood too proud, stronger yet placed before a weaker, the Kingβs hand rose. The judgment was clear β arrogance could not stand before humility.
π The Clash of Blades
swap(arr[j], arr[j + 1]);
And so they clashed. Steel rang, dust rose, and the stronger was forced back while the weaker advanced. This was no shame, only correction β for each must find his rightful place in the grand line of honor.
π The Endless Rounds
}
}
}
The tournament raged on. Round after round, duel after duel, the warriors reshaped themselves. Slowly, pride gave way to order. And when the final clash faded, the line stood perfect β weakest at the front, strongest at the end.
πΊ The Trial of Seven
int main() {
vector<int> arr = {64, 34, 25, 12, 22, 11, 90};
One dawn, seven warriors entered the arena: 64, 34, 25, 12, 22, 11, 90. They stood in chaos, their strength unmatched to their position. The crowd murmured, sensing the Kingβs displeasure.
bubbleSort(arr);
The horn sounded, and the duels began. One by one, the proud were forced back, the humble were lifted forward. The spell of bubbleSort was upon them, and the order was inevitable.
π The Final Parade
for (int x : arr) {
cout << x << " ";
}
cout << endl;
}
At last, the Herald called their names. One after another, they stepped forward in perfect order, weakest to strongest. The crowd cheered, for the line of warriors now mirrored the will of the King. The Tournament was complete.
π§ Memory of the Arena
- The outer loop β the rounds of the tournament, each settling one champion.
- The inner loop β the neighbor duels, brutal and swift.
- The if-condition β the Kingβs judgment on pride.
- The swap β the clash that corrects the line.
Thus Bubble Sort is remembered as the Tournament of the Shifting Blades, where every warrior found his rightful place. βοΈπ
Top comments (0)