Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Bubble Sort Algorithm Javascript Added #36

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
- Reysekha
- igrzhukovich
- CinnamonXI
- AkasakaID
- AkasakaID
- TayyabHussain03
33 changes: 33 additions & 0 deletions src/Javascript/TayyabHussain03.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Bubble sort Implementation using Javascript


// Creating the bblSort function
function bblSort(arr){

for(var i = 0; i < arr.length; i++){

// Last i elements are already in place
for(var j = 0; j < ( arr.length - i -1 ); j++){

// Checking if the item at present iteration
// is greater than the next iteration
if(arr[j] > arr[j+1]){

// If the condition is true then swap them
var temp = arr[j]
arr[j] = arr[j + 1]
arr[j+1] = temp
}
}
}
// Print the sorted array
console.log(arr);
}


// This is our unsorted array
var arr = [234, 43, 55, 63, 5, 6, 235, 547];


// Now pass this array to the bblSort() function
bblSort(arr);