Given,
AAA={34, 12, 56, 22, 43, 60}
In the bubble short, we are swapping the adjacent element if it is arranged in wrong order.
First Pass: {34, 12, 56, 22, 43, 60} Here, algorithm compares first two elements and swap, since 34>12
{12, 34, 56, 22, 43, 60} No swap, since 34<56
{12, 34, 22, 56, 43, 60} swap since 56>22
{12, 34, 22, 43, 56, 60} swap since 56>43
{12, 34, 22, 43, 56, 60} no swap because 56<60
Second Pass: {12, 34, 22, 43, 56, 60}
{12, 34, 22, 43, 56, 60} No swap, since 34>12
{12, 22, 34, 43, 56, 60} swap, since 34>22
{12, 22, 34, 43, 56, 60} swap, since 43>34
{12, 22, 34, 43, 56, 60} no swap, since 56>43
{12, 22, 34, 43,56, 60} no swap, since 60>56
Third Pass: {12, 22, 34, 43,56,60}
{12, 22, 34, 43,56,60} no swap, since 22>12
{12, 22, 34, 43,56,60} no swap, since 34>22
{12, 22, 34, 43,56,60} no swap, since 43>34
{12, 22, 34, 43,56,60} no swap, since 56>43
{12, 22, 34, 43,56,60} no swap, since 60>56
Comments
Leave a comment