2

Please Help. I am trying combine 2 classes (bubblesort4 and OddArrSe3), to get the answer from bubblesort4 to appear on OddArrSe3, such as on System.out.println ("Bubble Sort : ").

        What I am trying to do is get the answer for the coding below:
        System.out.println("Array Before Bubble Sort");
            for(int i=0; i < intArray.length; i++)
            {
                    System.out.print(intArray[i] + " ");
            }

            bubbleSort(intArray);

            System.out.println("");

            System.out.println("Array After Bubble Sort");
            for(int i=0; i < intArray.length; i++)
            {
                    System.out.print(intArray[i] + " ");

================================================================================= To appear on: System.out.println ("Bubble Sort : " + bubbleSort.sortBubble(intArray));

Any help would be appreciated. Thanks in advance. Below is the full coding

import java.util.ArrayList;
import java.util.List;
import java.util.*;

public class OddArrSe3
{
    public static void main(final String[] args)
    {
        int[] array_sort = {10,41,21,24,34,15,40,12,32,23,13,25,30,31,22,33,14,35,20,11};

        ArrayList<Integer> OddArr = new ArrayList<Integer>();
        ArrayList<Integer> EvenArr = new ArrayList<Integer>();

        for (int i : array_sort)    
        {
            if ((i & 1) == 1) 
            {
                OddArr.add(i);
            } 
            else 
            {
                EvenArr.add(i);
            }
         }

         Collections.sort(OddArr);
         Collections.sort(EvenArr);
         System.out.println("Odd:" + OddArr);
         System.out.println("Even:" + EvenArr);

          int OddArr2[] = {11, 13, 15, 21, 23, 25, 31, 33, 35, 41};
          int toSearch = 31;  

          int EvenArr2[] = {10, 12, 14, 20, 22, 24, 30, 32, 34, 40};
          int toSearch2 = 32;

          LinearSearch4 linearSearch = new LinearSearch4();  
          BinarySearch4 binarySearch = new BinarySearch4();  
          Bubblesort4 bubblesSort = new BubbleSort4();

          System.out.println("Linear Search Index : "  
          + linearSearch.searchLinear(OddArr2, toSearch));  
          System.out.println("Binary Search Index : "  
          + binarySearch.searchBinary(EvenArr2, toSearch2)); 
          System.out.println ("Bubble Sort : " + bubbleSort.sortBubble(intArray));
        }
 }

BubbleSort4

public class BubbleSort4 
{
    public static void main(String[] args) {

            int intArray[] = new int[]{5,90,35,45,150,3};

            System.out.println("Array Before Bubble Sort");
            for(int i=0; i < intArray.length; i++)
            {
                    System.out.print(intArray[i] + " ");
            }

            bubbleSort(intArray);

            System.out.println("");

            System.out.println("Array After Bubble Sort");
            for(int i=0; i < intArray.length; i++)
            {
                    System.out.print(intArray[i] + " ");
            }

     }

    private static void bubbleSort(int[] intArray) 
    {                            
            int n = intArray.length;
            int temp = 0;

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

                            if(intArray[j-1] > intArray[j])
                            {

                                    temp = intArray[j-1];
                                    intArray[j-1] = intArray[j];
                                    intArray[j] = temp;
                            }

                    }
            }    
    }

}

0 Answers0