# HELP! Bubble sort show by process

• 07-09-2012, 06:35 AM
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???
• 07-09-2012, 06:45 AM
Junky
Re: HELP! Bubble sort show by process
Quote:

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.
• 07-09-2012, 06:47 AM
JosAH
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
• 07-09-2012, 06:49 AM
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
• 07-09-2012, 06:51 AM
Junky
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
• 07-09-2012, 06:53 AM
Junky
Re: HELP! Bubble sort show by process
Quote:

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.
• 07-09-2012, 06:55 AM
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
• 07-09-2012, 06:58 AM
Junky
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?
• 07-09-2012, 07:00 AM
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 !!
• 07-09-2012, 07:01 AM
Junky
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!
• 07-09-2012, 07:03 AM
Re: HELP! Bubble sort show by process
what if you give me hints so that you could help me...

• 07-09-2012, 07:04 AM
Junky
Re: HELP! Bubble sort show by process
Quote:

Originally Posted by Junky
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!
• 07-09-2012, 07:05 AM
Junky
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?
• 07-09-2012, 07:06 AM
Re: HELP! Bubble sort show by process
your really not helping ..thanks for posting ur comment.,...
• 07-09-2012, 07:08 AM
Junky
Re: HELP! Bubble sort show by process
I am helping. You are just too stubborn to listen! Goodbye!
• 07-09-2012, 07:09 AM
Re: HELP! Bubble sort show by process
Listen???Whuat????

Do me a call and ill listen...

ahahahaha.....Ohh my!!
• 07-09-2012, 07:25 AM
JosAH
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