Why not use pointers?
pointer a = beginning
pointer b = end
while( a != b)
--b = ++a
Why not use pointers?
pointer a = beginning
pointer b = end
while( a != b)
--b = ++a
Now let's look at swapping two values. Say I have two variables, this and that. I can't start by saying either this=that (because then this goes away), or that=this (because then that goes away). I have to temporarily store one of them: temp = this. Now that I've stored the old value of this, I can put in the new value: this = that. And now finally I can replace that: that = temp. So it would look like
Code:temp = this; this = that; that = temp;
array[index]
the original array is to be a[n]
I need to put it reverese.
Is tabstop officially invisible? Take the very first bit of a, and the very last bit of a and swap those.
?Code:for( k=n-1; k>0;k--) temp = k; k = n; a[n] = temp;
Blast....
Code:int i, j, n, tmp, a[25]; n = 25; for(i = 0, j = n-1; i < j; ++i, --j) { tmp = a[j]; a[j] = a[i]; a[i] = tmp; }
brb and will look at this
Yeah definitely don't try to take in too much at once. This is where it gets pretty intense. Sorry... I really am feeling sick right now. I don't mean to be so.... irritable.
hmm yeah a bit confusing, but im checking it out. seems you declared more varialbles in that then me
ahh i see sonething
you are swapping the i and j
makes sense
but I was supposed to stick with only a n k and tep variables
Well whatever, they are just variables. Call them whatever you wish.
se ewhat i mean? i dont have that extra variable to useCode:for ( k=n-1; k>0;--k) { temp = a[k]; a[k = ?; ? = temp;
i mean i am supposed to complete the task without declaring any more variables
Ok... well you technically only need one counter if you know the original size: By the way, you just got me to have a second wind on this particular thread.
Example:
Code:for ( k=0; k < n;k++) { temp = a[k]; a[k] = a[n-k]; a[n-k] = temp; }
Last edited by master5001; 10-20-2008 at 07:45 PM. Reason: Crikey! I just noticed a boo boo.