0% found this document useful (0 votes)
139 views3 pages

Bubble Sort Algorithm Visualizer

The document explains how to implement a bubble sort algorithm to sort both strings and numbers. It includes code snippets to sort an array using bubble sort and output the array before and after sorting.

Uploaded by

Mohib Uddin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views3 pages

Bubble Sort Algorithm Visualizer

The document explains how to implement a bubble sort algorithm to sort both strings and numbers. It includes code snippets to sort an array using bubble sort and output the array before and after sorting.

Uploaded by

Mohib Uddin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LAB #04:

BUBBLE SORT ALGORITHM IMPLEMENTATION

Sorting A String Using Bubble Sort:

function BubbleSort(arr)
{

for(let i=0;i<[Link]-1;i++)
{
for(let j=0;j<[Link]-1;j++)
{
if(arr[j].charCodeAt(0)>arr[j+1].charCodeAt(0))
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
[Link](arr);
}

let input=[Link](".input");

let display=[Link](".unsortedarray");
let newdisplay=[Link](".sortedarray");
var arr=[];
function main()
{
//Every Textbox Value Will Be Stored In The Array
[Link]([Link]);
//Array Before Sorting
[Link]=arr;
//Sorting Function
BubbleSort(arr);
//Array After Sorting
[Link]=arr;

}
Visualization:

Sorting Numbers Using Bubble Sort:

function BubbleSort(arr)
{

for(let i=0;i<[Link]-1;i++)
{
for(let j=0;j<[Link]-1;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
[Link](arr);
}

let input=[Link](".input");

let display=[Link](".unsortedarray");
let newdisplay=[Link](".sortedarray");
var arr=[];
function main()
{
//Every Textbox Value Will Be Stored In The Array
[Link]([Link]);
//Array Before Sorting
[Link]=arr;
//Sorting Function
BubbleSort(arr);
//Array After Sorting
[Link]=arr;

Visualization:

You might also like