Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: need help with bubbe sort

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    My Mood
    Dead
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default need help with bubbe sort

     
     
    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"..


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default 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?

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    Daruga (November 23rd, 2013)

  4. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    My Mood
    Dead
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: need help with bubbe sort

    i mean how to writing bubble sort algorithm...

  5. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default 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.

  6. The Following User Says Thank You to jps For This Useful Post:

    Daruga (November 23rd, 2013)

  7. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    My Mood
    Dead
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: need help with bubbe sort

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

  8. #6
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    My Mood
    Dead
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: need help with bubbe sort

    i got this error on my binary search and linear search...
    what it meant?...this screenshottest.jpg

    for linear search get number from odd array and binary search form even array...
    need help how to fix...
    Attached Images Attached Images

  9. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default 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

  10. The Following User Says Thank You to jps For This Useful Post:

    Daruga (November 23rd, 2013)

  11. #8
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    My Mood
    Dead
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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

  12. #9
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default 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?

  13. The Following User Says Thank You to jps For This Useful Post:

    Daruga (November 23rd, 2013)

  14. #10
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    My Mood
    Dead
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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 ---

    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
      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...
     
    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

Similar Threads

  1. heap sort vs merge sort
    By IHeartProgramming in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 3rd, 2012, 04:37 AM
  2. Replies: 2
    Last Post: November 11th, 2012, 10:44 PM
  3. How to call a C sort function to sort a Java Array.
    By Dwere13 in forum Java Native Interface
    Replies: 22
    Last Post: July 12th, 2012, 04:44 PM
  4. How do I sort strings without using the sort method?
    By mjballa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 4th, 2011, 03:27 PM
  5. bubble sort and selection sort on strings
    By Sir Saula in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2010, 09:44 AM