Answers for "bubble sort syntax"

4

bubble sort in java

public static void bubbleSort(int arr[])
{
	for (int i = 0; i < arr.length; i++) //number of passes
    {
		//keeps track of positions per pass      
    	for (int j = 0; j < (arr.length - 1 - i); j++) //Think you can add a -i to remove uneeded comparisons 
        {
          	//if left value is great than right value 
        	if (arr[j] > arr[j + 1])
            {
              	//swap values
            	int temp = arr[j];
              	arr[j] = arr[j + 1];
              	arr[j + 1] = temp; 
            }
        }
    }
}
Posted by: Guest on April-15-2020
0

c++ buble sort

Psuedo code:

Procedure bubble_sort (array , N)
               array – list of items to be sorted
               N – size of array
begin
               swapped = false
               repeat
                             for I = 1 to N-1 
                                              if array[i-1] > array[i] then
                                                           swap array[i-1] and array[i]
                                                           swapped = true
                                              end if
                              end for
                until not swapped
end procedure
Posted by: Guest on November-30-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language