diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3ac0c91..d614e9c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,4 +20,5 @@ - Reysekha - igrzhukovich - CinnamonXI -- AkasakaID \ No newline at end of file +- AkasakaID +- TayyabHussain03 diff --git a/src/Javascript/TayyabHussain03.js b/src/Javascript/TayyabHussain03.js new file mode 100644 index 0000000..cf4ceb4 --- /dev/null +++ b/src/Javascript/TayyabHussain03.js @@ -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);