problem 2.1.2 from how to solve it by computer, Dromey

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
sathyashrayan
New poster
Posts: 6
Joined: Tue Apr 25, 2006 6:48 pm

problem 2.1.2 from how to solve it by computer, Dromey

Post by sathyashrayan » Sat Jul 28, 2012 7:38 pm

I am a beginner in learning algo..So please bear with me..

2.1.2 Design an algorithm that makes following exchanges of 3 varioubles..

a-->b-->c--|
^ |
^----------|


So
a_temp = a;
b_temp = b;
c_temp = c;

a=c_temp;
c=b_temp;
b=a_temp;

I know this process looks ugly. Can anyone suggest a good one so that I could learn.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: problem 2.1.2 from how to solve it by computer, Dromey

Post by brianfry713 » Mon Jul 30, 2012 10:35 pm

temp=a;
a=c;
c=b;
b=temp;
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Algorithms”