Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

bubbleSort

const bubbleSort = (arr) => {
  let temp = 0;
  for (let i = 0; i < arr.length; i++) {
    for (let j = 1; j < arr.length; j++) {
      if (arr[j - 1] > arr[i]) {
        temp = arr[j - 1];
        arr[j - 1] = arr[i];
        arr[i] = temp;
      }
    }
  }
  return arr;
};

console.log(bubbleSort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]));
 
PREVIOUS NEXT
Tagged: #bubbleSort
ADD COMMENT
Topic
Name
8+8 =