Ulf Dittmer i dont know my friend ! help me out i cant think ! i know the trick by using addition, sub , only for two variables . three variable i wonder ???
Originally posted by GUNA RANJAN: Ulf Dittmer i dont know my friend ! help me out i cant think ! i know the trick by using addition, sub , only for two variables . three variable i wonder ???
Think about it. Can you swap three variables? If you already have a way to switch two variables?
Maybe you can swap those three variables -- two at a time?
Maybe you can swap those three variables -- two at a time?
More than enough of a clue there. Since this sounds like a homework problem, I'm not going to tell you the answer.
However, suffice to say that using pairwise swaps you can achieve any number of permutations without using a "temp variable".
Note these techniques use (possibly more) space in the registers or CPU cache, so you really save nothing except 4 bytes of RAM by using them.
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / AmazonAmazon UK )
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
4
posted
0
Originally posted by GUNA RANJAN: hai friendz can any1 help me out !!!
I hadn't noticed that earlier. Use Real Words. You are not on a mobile, and not everybody here learned English as a first language; any1 and friendz are simply annoying.
Matt Swaggi
Ranch Hand
Joined: May 29, 2008
Posts: 61
posted
0
Campbell Ritchie please see you private message
Matt Swaggi
Ranch Hand
Joined: May 29, 2008
Posts: 61
posted
0
Thank You all the way which i worked is that correct ! if not denote my mistakes !
Swapping three variable without using temp variable
a = 2 b = 1 c = 3
a = a+b+c = 6
b = a -b-c = 2 c = a -b- c = 1 a = a-b-c = 3
After swaping
a = 3 ; b = 2 ; c = 1
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
4
posted
0
Originally posted by GUNA RANJAN: Campbell Ritchie please see you private message
Sorry if I was rude.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
4
posted
0
Yes, you have got it. Well done.
Matt Swaggi
Ranch Hand
Joined: May 29, 2008
Posts: 61
posted
0
Thats all right sir ! i just said what i felt ! i am always frank ! thank you once again ! and i will correct my mistakes !
Paul Sisco
Greenhorn
Joined: Jun 15, 2008
Posts: 11
posted
0
Originally posted by GUNA RANJAN: Thank You all the way which i worked is that correct ! if not denote my mistakes !
Swapping three variable without using temp variable
a = 2 b = 1 c = 3
a = a+b+c = 6
b = a -b-c = 2 c = a -b- c = 1 a = a-b-c = 3
After swaping
a = 3 ; b = 2 ; c = 1
This looks like a neat trick, but is there a real world application for it? I don't think I have ever considered doing anything like this in any language.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How will u swap three variable without using temp variable !??