Show the contents of the array {43, 7, 190,23,18, 5,86,14} (sort in ascending order) after the first two iterations of Selection Sort. How many comparisons would be needed to sort an array containing 10 elements using Bubble sort in the worst case

Respuesta :

Using the knowledge in computational language in JAVA it is possible to write a code that organizes the values ​​in larger and smaller in arguments.

Writing the code in JAVA we have:

class SSort

{

   void sort(int array[])

   {

       int n = array.length;

       for (int i = 0; i < 2; i++)

       {

           int minimum_index = i;

           for (int j = i+1; j < n; j++)

               if (array[j] < array[minimum_index])

                   minimum_index = j;

            int temp = array[minimum_index];

           array[minimum_index] = array[i];

           array[i] = temp;

       }

   }

    void printArray(int array[])

   {

       int n = array.length;

       for (int i=0; i<n; ++i)

           System.out.print(array[i]+" ");

       System.out.println();

   }

   public static void main(String args[])

   {

       SSort s = new SSort();

       int array[] = {43,7,190,23,18,5,86,14};

       s.sort(array);

       System.out.println("After first two iteration of Selection sort:");

       s.printArray(array);

   }

}

See more about JAVA at brainly.com/question/12975450

#SPJ1

Ver imagen lhmarianateixeira
Ver imagen lhmarianateixeira