App/script.js
// BubbleSort() : Implementation of bubble sort algorithm. O(n^2)
BubbleSort() : Implementation of bubble sort algorithm.
BubbleSort () : Implementation of bubble sort algorithm .
async function BubbleSort() {
	let delay = Disable_The_Input();
	let container = document.getElementById("container");
	for (let i = 0; i < bars.length - 1; i++) {
		let has_swap = false;
		for (let j = 0; j < bars.length - i - 1; j++) {
			let curr_id = bars[j].split('id="')[1].split('"')[0];
			let nxt_ele = bars[j + 1].split('id="')[1].split('"')[0];
			document.getElementById(curr_id).style.backgroundColor = selected;
			let sound = MapRange(document.getElementById(curr_id).style.height.split('%')[0], 2, 100, 500, 1000);
			beep(100, sound, delay)
			document.getElementById(nxt_ele).style.backgroundColor = chng;
			await Sleep(delay / 2);
			let a = parseInt(bars[j].split(/[:%]/)[1]);
			let b = parseInt(bars[j + 1].split(/[:%]/)[1]);
			if (a > b) {
				has_swap = true;
				let t = bars[j];
				bars[j] = bars[j + 1];
				bars[j + 1] = t;
				container.innerHTML = bars.join('');
			}
			document.getElementById(curr_id).style.backgroundColor = selected;
			document.getElementById(nxt_ele).style.backgroundColor = chng;
			await Sleep(delay / 2.0);
			document.getElementById(curr_id).style.backgroundColor = def;
			document.getElementById(nxt_ele).style.backgroundColor = def;
		}
		if (has_swap == false) break;
	}
	Finished_Sorting();
}
async function BubbleSort ( ) { let delay = Disable_The_Input ( ) ; let container = document . getElementById ( "container" ) ; for ( let i = 0 ; i < bars . length - 1 ; i ++ ) { let has_swap = false ; for ( let j = 0 ; j < bars . length - i - 1 ; j ++ ) { let curr_id = bars [ j ] . split ( 'id="' ) [ 1 ] . split ( '"' ) [ 0 ] ; let nxt_ele = bars [ j + 1 ] . split ( 'id="' ) [ 1 ] . split ( '"' ) [ 0 ] ; document . getElementById ( curr_id ) . style . backgroundColor = selected ; let sound = MapRange ( document . getElementById ( curr_id ) . style . height . split ( '%' ) [ 0 ] , 2 , 100 , 500 , 1000 ) ; beep ( 100 , sound , delay ) document . getElementById ( nxt_ele ) . style . backgroundColor = chng ; await Sleep ( delay / 2 ) ; let a = parseInt ( bars [ j ] . split ( / [:%] / ) [ 1 ] ) ; let b = parseInt ( bars [ j + 1 ] . split ( / [:%] / ) [ 1 ] ) ; if ( a > b ) { has_swap = true ; let t = bars [ j ] ; bars [ j ] = bars [ j + 1 ] ; bars [ j + 1 ] = t ; container . innerHTML = bars . join ( '' ) ; } document . getElementById ( curr_id ) . style . backgroundColor = selected ; document . getElementById ( nxt_ele ) . style . backgroundColor = chng ; await Sleep ( delay / 2.0 ) ; document . getElementById ( curr_id ) . style . backgroundColor = def ; document . getElementById ( nxt_ele ) . style . backgroundColor = def ; } if ( has_swap == false ) break ; } Finished_Sorting ( ) ; }
BubbleSort() : Implementation of bubble sort algorithm.
BubbleSort () : Implementation of bubble sort algorithm .