Re: swap two integers without using a tmp variable?
From: Richard Herring (junk_at_[127.0.0.1)
Date: 06/22/04
- Next message: Ioannis Vranos: "Re: include headers: <X>, <X.h> and global namespaces"
- Previous message: Roman Ziak: "Re: To Borland Builder or to Visual Studio"
- In reply to: Steve: "Re: swap two integers without using a tmp variable?"
- Next in thread: Mike Smith: "Re: swap two integers without using a tmp variable?"
- Reply: Mike Smith: "Re: swap two integers without using a tmp variable?"
- Reply: puppet_sock_at_hotmail.com: "Re: swap two integers without using a tmp variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 22 Jun 2004 14:03:04 +0100
In message <976e0586.0406220444.4ed62241@posting.google.com>, Steve
<ngsteve@my-deja.com> writes
>The xor solution was really elegant. I would not have thought about it
>and never knew it could be done this way.
> X XOR Y XOR Y = X (assign in y variable, cancel out both Y)
> X XOR Y XOR X = Y (assign in x variable, cancel out both X)
And it DOESN'T WORK (no apologies for shouting) if X and Y are both
references to the same object. Don't do it!
-- Richard Herring
- Next message: Ioannis Vranos: "Re: include headers: <X>, <X.h> and global namespaces"
- Previous message: Roman Ziak: "Re: To Borland Builder or to Visual Studio"
- In reply to: Steve: "Re: swap two integers without using a tmp variable?"
- Next in thread: Mike Smith: "Re: swap two integers without using a tmp variable?"
- Reply: Mike Smith: "Re: swap two integers without using a tmp variable?"
- Reply: puppet_sock_at_hotmail.com: "Re: swap two integers without using a tmp variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|