Thread: this is fun but Im new and confused

  1. #31
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Why not use pointers?

    pointer a = beginning
    pointer b = end

    while( a != b)
    --b = ++a

  2. #32
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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;

  3. #33
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    array[index]

  4. #34
    Registered User
    Join Date
    Oct 2008
    Location
    new york
    Posts
    25
    the original array is to be a[n]
    I need to put it reverese.

  5. #35
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Is tabstop officially invisible? Take the very first bit of a, and the very last bit of a and swap those.

  6. #36
    Registered User
    Join Date
    Oct 2008
    Location
    new york
    Posts
    25
    Code:
     for( k=n-1; k>0;k--)
       temp = k;
      k = n;
     a[n] = temp;
    ?

  7. #37
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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;
    }

  8. #38
    Registered User
    Join Date
    Oct 2008
    Location
    new york
    Posts
    25
    brb and will look at this

  9. #39
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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.

  10. #40
    Registered User
    Join Date
    Oct 2008
    Location
    new york
    Posts
    25
    hmm yeah a bit confusing, but im checking it out. seems you declared more varialbles in that then me

  11. #41
    Registered User
    Join Date
    Oct 2008
    Location
    new york
    Posts
    25
    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

  12. #42
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well whatever, they are just variables. Call them whatever you wish.

  13. #43
    Registered User
    Join Date
    Oct 2008
    Location
    new york
    Posts
    25
    Code:
     for ( k=n-1; k>0;--k) {
      temp = a[k];
      a[k = ?;
      ? = temp;
    se ewhat i mean? i dont have that extra variable to use

  14. #44
    Registered User
    Join Date
    Oct 2008
    Location
    new york
    Posts
    25
    i mean i am supposed to complete the task without declaring any more variables

  15. #45
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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.

Popular pages Recent additions subscribe to a feed