2013-12-09 33 views
-3

請幫助。我想結合2個類(bubblesort4和OddArrSe3),以獲得來自bubblesort4的出現在OddArrSe3上的答案,如System.out.println ("Bubble Sort : ")。任何幫助,將不勝感激。
如何結合OddArr和Bubble排序

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 : ") 
     } 
} 


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; 
           } 

         } 
       }  
     } 
} 
+2

丟失;在System.out.println(「Bubble Sort:」)之後 –

+0

好主,請閱讀Java的命名約定。 – christopher

+0

「我試過,但我保持....」 - 你究竟做了什麼?你得到了什麼確切的錯誤信息? – DanielBarbarian

回答

1
System.out.println ("Bubble Sort : ") 

將其更改爲

System.out.println ("Bubble Sort : "); 
+0

也許這是代碼中的許多錯誤之一.... – alphacentauri

+0

這是他所指的那個。 –

+0

Tahnks的幫助,但我希望從泡沫sprt得到的答案出現在System.out.println(「泡沫排序:」); – user3082700