at line 1(ie as indicated ------------------->(1) ) ,I can never reach table[i] =table[j] ,but still the code executes and if possible plz expalin how the code works. I tried but i am very confused. Plz explain me passing array refernces ,if possible or let me know where can i chekc it out in detail.
[ EJFH: Added UBB Code tags ] [ January 07, 2005: Message edited by: Ernest Friedman-Hill ]
Ernest Friedman-Hill
author and iconoclast
Marshal
I also echo Ernest's question as to what your question is since your code does reach line 1. I suspect that the issue is that it is not doing what you think it should do.
prerna boja
Ranch Hand
Joined: Aug 19, 2004
Posts: 67
posted
0
Hi,
I mean to say that
see when the method public static void swap(int[] table,int i,int j) is called it does all the calculations in the method.
i mean when it is called first int tmp= table[0] (ie index-1 = int i ,so i =0)=>tmp = 6 (as table[0]=dataSeq[0])
then
table[i] = table[j] => table[0]=table[1] => 6=4.
(in this way it goes but it is never equal so how can it reach the nxt statement then again go back to the for loop n start the process again by increamenting the index.)
then
table[j]=tmp; =>table[1]=6;
Ernest Friedman-Hill
author and iconoclast
Marshal
is an instruction, not a test. It means that Java should take the value in table[i], and copy it into table[j]. The "=" operator always means this. The "==" operator -- two equals signs together -- is a test for equality.
prerna boja
Ranch Hand
Joined: Aug 19, 2004
Posts: 67
posted
0
Hi,
I got it .Thanks for the reply.
But I got stuck up again when I started to work out i get
the output as
dataSeq[1] =6 dataSeq[3] =8 dataSeq[4] =2
but never able to reach dataSeq[0] and dataSeq[2]
Thanks Once again to help me out.
Jeff Bosch
Ranch Hand
Joined: Jul 30, 2003
Posts: 804
posted
0
It works for me. When I run your program, I get:
Give a man a fish, he'll eat for one day. <br />Teach a man to fish, he'll drink all your beer.<br /> <br />Cheers,<br /> <br />Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Steven Bell
Ranch Hand
Joined: Dec 29, 2004
Posts: 1071
posted
0
I'm not sure what you did. The first code you posted executes exactly as it should.
To me it looks like the first pass of a bubble sort. If it is you would need to add another for loop around the first one to loop the lenght of the array.
If not it would help if you were to explain what you are trying to do.