Results 1 to 17 of 17
  1. #1
    BadAlligator is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default HELP! Bubble sort show by process

    Here is my code

    public class bubbleSort{
    public static void main(String a[]){
    int i;
    int array[] = {12,9,4,99,120,1,3,10};
    System.out.println("Values Before the sort:\n");
    for(i = 0; i < array.length; i++)
    System.out.print( array[i]+" ");
    System.out.println();
    bubble_srt(array, array.length);
    System.out.print("Values after the sort:\n");
    for(i = 0; i <array.length; i++)
    System.out.print(array[i]+" ");
    System.out.println();
    System.out.println("PAUSE");
    }

    public static void bubble_srt( int a[], int n ){
    int i, j,t=0;
    for(i = 0; i < n; i++){
    for(j = 1; j < (n-i); j++){
    if(a[j-1] > a[j]){
    t = a[j-1];
    a[j-1]=a[j];
    a[j]=t;
    }
    }
    }
    }
    }


    This is my output:
    Values Before the sort:
    12 9 4 99 120 1 3 10
    Values after the sort:
    1 3 4 9 10 12 99 120
    PAUSE


    The output i want :
    PROCCESS 1:9 4 12 99 120 1 3 10
    PROCCESS 2:9 4 12 99 120 1 3 10
    PROCCESS 3:9 4 12 99 1 120 3 10
    PROCCESS 4:9 4 12 99 1 120 3 10
    PROCCESS 5:9 4 12 99 1 3 120 10
    PROCCESS 6:9 4 12 99 1 3 10 120

    someone who can help me???

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: HELP! Bubble sort show by process

    Quote Originally Posted by BadAlligator View Post
    someone who can help me???
    Help with what? Ask a specific question and get a specific answer.

    If you want your output to look like that then you are going to need more print statements.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default Re: HELP! Bubble sort show by process

    At the end of each pass through the inner loop of your sort method you have to print the array; b.t.w. you're looping too many times, but you'll see that yourself after you've fixed your current problem.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    BadAlligator is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default Re: HELP! Bubble sort show by process

    how could i do that???

    i dont have the knowledge... would you lend me your knowledge and help me to have an output like this???

    The output i want :
    PROCCESS 1:9 4 12 99 120 1 3 10
    PROCCESS 2:9 4 12 99 120 1 3 10
    PROCCESS 3:9 4 12 99 1 120 3 10
    PROCCESS 4:9 4 12 99 1 120 3 10
    PROCCESS 5:9 4 12 99 1 3 120 10
    PROCCESS 6:9 4 12 99 1 3 10 120

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: HELP! Bubble sort show by process

    BTW your expected output is not correct. If you implement the bubblesort algorithm correctly then 120 should "bubble" all the way to the end on the first sweep. So the list should look like: 9 4 12 99 1 3 10 120

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: HELP! Bubble sort show by process

    Quote Originally Posted by BadAlligator View Post
    how could i do that???

    i dont have the knowledge...
    Yes you do. In your current code you have plenty of print statements. So you know how to write them. All you need to do now is work out what print statement you want and where to put it. You can either waste a lot of time through trial and error or you can use some logic to work it out.

  7. #7
    BadAlligator is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default Re: HELP! Bubble sort show by process

    oh yeah like THIS
    The output i want :
    PROCCESS 1:9 4 12 99 120 1 3 10
    PROCCESS 2:9 4 12 99 1 120 3 10
    PROCCESS 3:9 4 12 99 1 120 3 10
    PROCCESS 4:9 4 12 99 1 3 120 10
    PROCCESS 5:9 4 12 99 1 3 10 120

    i just wanna show the process of bubble sort ...
    Can you help me do it..
    i dont really have an idea

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: HELP! Bubble sort show by process

    Sounds like you are just expecting someone to spoonfeed you the answer. How about trying! If you want something to print out the use a print statement to do it. Then use you brain to work out where that print statement goes. If you want it to happen many times then what does that suggest to you?

  9. #9
    BadAlligator is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default Re: HELP! Bubble sort show by process

    you just comment but dont really help...

    stop commenting...its not helping me...

    Dont post here to gain reputations...

    we dont need you ....

    I post here to learn how to do it..

    not for someone to post on it to gain reputation ..

    Thank you ...

    Good bye.... For ever !!

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: HELP! Bubble sort show by process

    I can comment as much as I like. Another comment I would like to make is that this community will not miss you!

  11. #11
    BadAlligator is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default Re: HELP! Bubble sort show by process

    what if you give me hints so that you could help me...


    Or please stop commenting and wasting your time !!

  12. #12
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: HELP! Bubble sort show by process

    Quote Originally Posted by Junky View Post
    If you want it to happen many times then what does that suggest to you?
    I gave you plenty of hints and expected you to work it out for yourself instead of being spoonfed where you learn nothing. The above is a huge hint!

  13. #13
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: HELP! Bubble sort show by process

    Here's another hint: in your code you have some code which prints out the list before and after sorting. Why not move that into it's own method which you can call as many times as you want?

  14. #14
    BadAlligator is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default Re: HELP! Bubble sort show by process

    your really not helping ..thanks for posting ur comment.,...

  15. #15
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: HELP! Bubble sort show by process

    I am helping. You are just too stubborn to listen! Goodbye!

  16. #16
    BadAlligator is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default Re: HELP! Bubble sort show by process

    Listen???Whuat????

    Do me a call and ill listen...

    ahahahaha.....Ohh my!!

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default Re: HELP! Bubble sort show by process

    I'm closing this thread; the OP seems too stubborn to read the hints given by repliers.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Help with Bidirectional Bubble Sort
    By ankiit in forum New To Java
    Replies: 1
    Last Post: 05-02-2012, 03:36 PM
  2. Question with bubble sort
    By Metastar in forum New To Java
    Replies: 22
    Last Post: 09-13-2010, 06:25 AM
  3. Bubble sort
    By pineapple in forum New To Java
    Replies: 3
    Last Post: 04-25-2009, 12:45 AM
  4. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM
  5. need help with bubble sort
    By lowpro in forum New To Java
    Replies: 3
    Last Post: 12-17-2007, 05:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •