Results 1 to 17 of 17
- 07-09-2012, 06:35 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 10
- Rep Power
- 0
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 #2
- 07-09-2012, 06:47 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-09-2012, 06:49 AM #4
Member
- Join Date
- Jul 2012
- Posts
- 10
- Rep Power
- 0
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 #5
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 #6
Re: HELP! Bubble sort show by process
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 #7
Member
- Join Date
- Jul 2012
- Posts
- 10
- Rep Power
- 0
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 #8
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 #9
Member
- Join Date
- Jul 2012
- Posts
- 10
- Rep Power
- 0
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 #10
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 #11
Member
- Join Date
- Jul 2012
- Posts
- 10
- Rep Power
- 0
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 !!
- 07-09-2012, 07:04 AM #12
- 07-09-2012, 07:05 AM #13
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 #14
Member
- Join Date
- Jul 2012
- Posts
- 10
- Rep Power
- 0
Re: HELP! Bubble sort show by process
your really not helping ..thanks for posting ur comment.,...
- 07-09-2012, 07:08 AM #15
Re: HELP! Bubble sort show by process
I am helping. You are just too stubborn to listen! Goodbye!
- 07-09-2012, 07:09 AM #16
Member
- Join Date
- Jul 2012
- Posts
- 10
- Rep Power
- 0
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 #17
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Help with Bidirectional Bubble Sort
By ankiit in forum New To JavaReplies: 1Last Post: 05-02-2012, 03:36 PM -
Question with bubble sort
By Metastar in forum New To JavaReplies: 22Last Post: 09-13-2010, 06:25 AM -
Bubble sort
By pineapple in forum New To JavaReplies: 3Last Post: 04-25-2009, 12:45 AM -
How to sort a list using Bubble sort algorithm
By Java Tip in forum AlgorithmsReplies: 3Last Post: 04-29-2008, 08:04 PM -
need help with bubble sort
By lowpro in forum New To JavaReplies: 3Last Post: 12-17-2007, 05:27 PM


LinkBack URL
About LinkBacks


Bookmarks