javascript bubleshort example
JavaScript
bubbleSort(Array) {
let len = Array.length;
for (let i = 0; i < len; i++) { //you can also use "for in", so you don't need the variable "len"
for (let j = 0; j < len; j++) {
if (Array[j] > Array[j + 1]) {
let tmp = Array[j];
Array[j] = Array[j + 1];
Array[j + 1] = tmp;
}
}
}
return Array;
};function bubblesort(array) {
len = array.length;
for (let i = 0; i < len; i++) {
for (let j = 0; j < len - i; j++) {
let a = array[j];
if (a != array[-1]) {
var b = array[j + 1];
if (a > b) {
array[j] = b;
array[j + 1] = a;
}
}
}
}
}
let array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
bubblesort(array);
console.log(array)// like using Array.reverse();
function bubbleReverse(arr) {
for (let i = arr.length - 1; i > 0; i--) {
for (let j = arr.length - 1; j > 0; j--) {
if (arr[j] > arr[j - 1]) {
let temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
return arr;
}
// like using Array.sort();
function bubbleSort(arr) {
for (let i = 0; i < arr.length - 1; i++) {
for (let j = 0; j < arr.length - 1; j++) {
if (arr[j] > arr[j + 1]) {
let temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
return arr;
}
Also in JavaScript:
- Title
- how to remove an object from array in react native
- Category
- JavaScript
- Title
- command to create custom pipe in angular 6
- Category
- JavaScript
- Title
- bind jquery trough name
- Category
- JavaScript
- Title
- inline z-index react
- Category
- JavaScript
- Title
- events js 292 throw er Unhandled 'error' event ^ Error getaddrinfo ENOTFOUND x86_64-apple-darwin13.4.0 at GetAddrInfoReqWrap.onlookup [as oncomplete]
- Category
- JavaScript
- Title
- how to make a textarea unwritable in react native
- Category
- JavaScript
- Title
- * http://sizzlejs.com/
- Category
- JavaScript
- Title
- data-widget="pushmenu" collable automatically
- Category
- JavaScript
- Title
- how to loop through array of numbers in javascript
- Category
- JavaScript
- Title
- firebase app named default already exists react native
- Category
- JavaScript
- Title
- express js redirect to url
- Category
- JavaScript
- Title
- javascript ascii to hex
- Category
- JavaScript
- Title
- daterangepicker set maxdate
- Category
- JavaScript
- Title
- eval in js
- Category
- JavaScript
- Title
- add element to array javascript
- Category
- JavaScript
- Title
- angular attach component to body
- Category
- JavaScript
- Title
- how to remove session data on tab close in redux\
- Category
- JavaScript
- Title
- javascript array concat spread operator
- Category
- JavaScript
- Title
- how to add role in discord.js v12
- Category
- JavaScript
- Title
- after click text editior open in javascript
- Category
- JavaScript
- Title
- add elements to an array with splice
- Category
- JavaScript
- Title
- Javascript clear canvas
- Category
- JavaScript
- Title
- angular submit form programmatically
- Category
- JavaScript
- Title
- javascript break inner loop only
- Category
- JavaScript
- Title
- get date now javascript
- Category
- JavaScript
- Title
- display none after hover
- Category
- JavaScript
- Title
- check object in array javascript
- Category
- JavaScript
- Title
- how to pass a variable to jspf
- Category
- JavaScript
- Title
- how to square a value in javascript
- Category
- JavaScript
- Title
- boucle for in js
- Category
- JavaScript
- Title
- getelementbyclass
- Category
- JavaScript
- Title
- how to remove the id in mongoose schema
- Category
- JavaScript
- Title
- append rotated triangle in anchor tag
- Category
- JavaScript
- Title
- get page resolution jquery
- Category
- JavaScript
- Title
- function js
- Category
- JavaScript
- Title
- how to verify timestamp format in javascript
- Category
- JavaScript
- Title
- how to Write a program that simulates a coin toss using random method of Javascript Math class
- Category
- JavaScript
- Title
- chartjs lineTension
- Category
- JavaScript
- Title
- how to deap clone an object in javascript
- Category
- JavaScript
- Title
- getelementbyid
- Category
- JavaScript
- Title
- Javascript change element class
- Category
- JavaScript
- Title
- extend react.component
- Category
- JavaScript
- Title
- image continuous changing div
- Category
- JavaScript
- Title
- how to make dynamic columns in jquery
- Category
- JavaScript
- Title
- how to version a react app azure pipelines
- Category
- JavaScript
- Title
- how to push object in array using for loop javascript
- Category
- JavaScript
- Title
- how to parse header in node.js lambda
- Category
- JavaScript
- Title
- class component react
- Category
- JavaScript
- Title
- javascript clear file input
- Category
- JavaScript
- Title
- dont starve together
- Category
- JavaScript
- Title
- javascript change web page title
- Category
- JavaScript
- Title
- capitalize all letters jquery
- Category
- JavaScript
- Title
- HTML5 Accesskey Attribute: you may not need JavaScript to add Keyboard Shortcuts
- Category
- JavaScript
- Title
- how to sepaarte text in object javascript
- Category
- JavaScript
- Title
- iterate through array javascript
- Category
- JavaScript
- Title
- export apk react native
- Category
- JavaScript
- Title
- async fetch api call
- Category
- JavaScript
- Title
- how to authenticate token in react using axios
- Category
- JavaScript
- Title
- click doesn't work on ajax loaded data
- Category
- JavaScript
- Title
- box shadow javascript style change
- Category
- JavaScript
- Title
- how to convert time to am pm in javascript
- Category
- JavaScript
- Title
- beautify json python
- Category
- JavaScript
- Title
- hello world javascript
- Category
- JavaScript
- Title
- convert boolean to string javascript
- Category
- JavaScript
- Title
- for of loop syntax javascript
- Category
- JavaScript
- Title
- how to use js console log
- Category
- JavaScript
- Title
- javascript click button by id
- Category
- JavaScript
- Title
- how to sort array least to greatest javascript
- Category
- JavaScript
- Title
- angularjs make post request
- Category
- JavaScript
- Title
- angular material multi select ngmodel
- Category
- JavaScript
- Title
- Add object to array javascript
- Category
- JavaScript
- Title
- angular build production
- Category
- JavaScript
- Title
- is object js
- Category
- JavaScript
- Title
- ascii to char in javascript
- Category
- JavaScript
- Title
- .push js
- Category
- JavaScript
- Title
- convert dictionary to json serialization swift 4
- Category
- JavaScript
- Title
- get and set es6
- Category
- JavaScript
- Title
- delete js
- Category
- JavaScript
- Title
- if condition in class angular 8
- Category
- JavaScript
- Title
- add class javascript
- Category
- JavaScript
- Title
- go to another page using javascript
- Category
- JavaScript
- Title
- ionic (Emitted value instead of an instance of Error
- Category
- JavaScript
- Title
- block comment js
- Category
- JavaScript
- Title
- console log all array values node
- Category
- JavaScript
- Title
- include jquery
- Category
- JavaScript
- Title
- custom status discord bot
- Category
- JavaScript
- Title
- iterate through list javascript
- Category
- JavaScript
- Title
- javascript access pushed element
- Category
- JavaScript
- Title
- graphql react filtering
- Category
- JavaScript
- Title
- window location in react
- Category
- JavaScript
- Title
- contact form7 404 wp-json feedback
- Category
- JavaScript
- Title
- how the map function works javascript
- Category
- JavaScript
- Title
- how to add attribute to selected element in javascript
- Category
- JavaScript
- Title
- get last item in array js
- Category
- JavaScript
- Title
- create dice game javascript
- Category
- JavaScript
- Title
- angular sumar labels
- Category
- JavaScript
- Title
- google sign in in firebase react
- Category
- JavaScript
- Title
- datetime to date javascript
- Category
- JavaScript
- Title
- javascript check empty object
- Category
- JavaScript
- Title
- how to prevent event capturing in javascript
- Category
- JavaScript