Answers for "bubble sort meaning"

1

Bubble Sort

#Bubble Sort
nums = [9, 4, 5, 1, 3, 7, 6]
for i in range(len(nums)):
    for j in range(1, len(nums)):
        if nums[j] < nums[j - 1]:
            nums[j], nums[j - 1] = nums[j - 1], nums[j]
Posted by: Guest on August-15-2021
0

c++ buble sort

void bubbleSort(int arr[], int size){
  int temp = int();
  //print out the unsorted values
  for ( int i = 0; i < size -1; i ++)
    cout << arr[i] << "\t";
  cout << endl << endl;
  
  
  for (int i = 1; i < size; i++ ){
  	for(int j = 0; j < size - i ; j ++){//size-i is the sorted part of the array	
   		if( arr[j] > arr[j + 1]){//if the value is greater than the next value in the array, swap it
          temp = arr[j];
          arr[j] = arr[j+1];//swap the two values
          arr[j+1] = temp;
          
        }//end if
    }//end for
  }//end for
  
}//end bubbleSort
Posted by: Guest on November-30-2020
3

bubble sort code

func Sort(arr []int) []int {
	for i := 0; i < len(arr)-1; i++ {
		for j := 0; j < len(arr)-i-1; j++ {
			if arr[j] > arr[j+1] {
				temp := arr[j]
				arr[j] = arr[j+1]
				arr[j+1] = temp
			}
		}
	}
	return arr
}
Posted by: Guest on August-16-2020
0

bubble sort algorithm

#include <bits/stdc++.h>

using namespace std;

void bubbleSort(int arr[], int n){
    int temp,i,j;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(arr[i] > arr[j]){
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
    }
}

int main(){
    int arr[] = {1,7,33,9,444,2,6,33,69,77,22,9,3,11,5,2,77,3};
    int n = sizeof(arr) / sizeof(arr[0]);

    bubbleSort(arr, n);

    for(int i=0;i<n;i++){
        cout << arr[i] << " ";
    }

    return 0;

}
Posted by: Guest on January-16-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language