# need help with bubbe sort

• November 22nd, 2013, 09:10 AM
Daruga
need help with bubbe sort
Code Java:

```    int numbers[] = new int[]{10,41,21,24,34,15,40,12,32,23,13,25,30,31,22,33,14,35,20,11}; for(int i=0; i < numbers.length; i++){     if(numbers[i]%2 == 0){ System.out.println(numbers[i] + " is even number."); java.util.Arrays.sort(numbers); // java.util.bubbleSort(numbers);(the problem is here...         }   { System.out.println(numbers[i] + " is odd number."); java.util.Arrays.sort(numbers); } }```

i need explanation how to use bubble sort coding...i did learn from tutorial but abit confusing...

--- Update ---

the other question is....about "binary search in even arr and find out the location of number 32 and display the location of the number 32 on the screen"..
• November 22nd, 2013, 09:31 AM
GregBrannon
Re: need help with bubbe sort
What are you confused about in using/writing a bubble sort algorithm? It's probably one of the best documented sorting approaches on the Internet, so you might want review more than one tutorial/discussion before giving up.

Your other question looks more like a statement taken from an assignment than a question. What's your question about it?
• November 22nd, 2013, 09:32 PM
Daruga
Re: need help with bubbe sort
i mean how to writing bubble sort algorithm...
• November 22nd, 2013, 09:52 PM
jps
Re: need help with bubbe sort
Write out the steps necessary to implement the sort, then translate that to syntax. If you get stuck, post your list of steps and code here with your question. We do not provide answers in code on the forum.
Explain exactly what it is you are stuck on. "How to implement bubble sort" is not specific, it is the whole topic.
• November 23rd, 2013, 09:00 AM
Daruga
Re: need help with bubbe sort
Code Java:

``` int numList[] = {10,41,21,24,34,15,40,12,32,23,13,25,30,31,22,33,14,35,20,11}; List<Integer> odd = new ArrayList<Integer>(); List<Integer> even = new ArrayList<Integer>();     int toSearch1 = 31; int toSearch2 = 41; LinearSearch linearSearch = new LinearSearch(); BinarySearch binarySearch = new BinarySearch();       for (int i :numList) { if (i % 2 ==0) { odd.add(i); } else {   even.add(i); }   } //Bubblesort(odd); Collections.sort(odd); Collections.sort(even); System.out.println( " Even number :" + odd ); System.out.println("Odd number :" + even );       System.out.println("Linear Search Index : " + linearSearch.searchElementLinear(odd, toSearch1)); System.out.println("Binary Search Index : " + binarySearch.searchElementBinary(even, toSearch2));   } }```
• November 23rd, 2013, 09:03 AM
Daruga
Re: need help with bubbe sort
i got this error on my binary search and linear search...
what it meant?...this screenshotAttachment 2490

for linear search get number from odd array and binary search form even array...
need help how to fix...
• November 23rd, 2013, 04:28 PM
jps
Re: need help with bubbe sort
Please copy paste the full text of any error messages to the forum and not as a screenshot or attachment
• November 23rd, 2013, 05:52 PM
Daruga
Re: need help with bubbe sort
it say: method search ElementLinear in class LinearSearch cannot be applied to given type;

required:int[], int

found:java.ulti.list<java.lang.integer>,int

reason:actual argument java.ulti.lst<java.lang.integer>cannot be converted to int[] by method invocation conversion
• November 23rd, 2013, 06:36 PM
jps
Re: need help with bubbe sort
That means the method requires int[], but was given List<Integer>
An array of int is not the same thing as a List of Integer
In the code even and odd are both variables of type List<Integer>. Change them to int arrays ( int[] ) or convert them to int arrays for the method call
Off topic.. what happened to doing bubble sort?
• November 23rd, 2013, 08:47 PM
Daruga
Re: need help with bubbe sort
ok i try first....then for the bubble sort i change to collection sort..it abit hard for me to implement the bubble sort...

--- Update ---

Quote:

In the code even and odd are both variables of type List<Integer>. Change them to int arrays ( int[] ) or convert them to int arrays for the method call
Code Java:

``` List<Integer> odd = new ArrayList<Integer>(); List<Integer> even = new ArrayList<Integer>();     System.out.println("Linear Search Index : " + linearSearch.searchElementLinear(odd, toSearch)); System.out.println("Binary Search Index : " + binarySearch.searchElementBinary(even, toSearch));```

--- Update ---

this what i comeout...
Code Java:

```  int odd1[] = {11, 13, 15, 21, 23, 25, 31, 33, 35, 41}; int even1[] = {10, 12, 14, 20, 22, 24, 30, 32, 34, 40}; int toSearch = 31; int toSearch2 =32;     System.out.println("Linear Search Index : " + linearSearch.searchElementLinear(odd1, toSearch)); System.out.println("Binary Search Index : " + binarySearch.searchElementBinary(even1, toSearch2));```

--- Update ---

the output..

Even number :[10, 12, 14, 20, 22, 24, 30, 32, 34, 40]
Odd number :[11, 13, 15, 21, 23, 25, 31, 33, 35, 41]
Linear Search Index : 6
Binary Search Index : 7