Results 1 to 8 of 8

Thread: Removing Doubles from an Array

  1. #1

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yep, i was at uni and i don't have a compiler there, it should be the other way around
    *(ib+=*ia==*ib)=*ia++
    which means the target will only increment when the values are equal.
    Notice the target iterator ib will the last result value, meaning you cut of the last numbers, also ib<&both[MAX_LENGTH_BOTH] not ia
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  2. #2
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    k i made the changes:
    for(int* ia=both,* ib=both;ib<&both[MAX_LENGTH_BOTH];*(ib+=*ia==*ib)=*ia++;

    get a parse error somewhere in there.

    D!m
    Dim

  3. #3

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    did you forget the closing parentesis for for( ; ; );
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Put the last one in and the output is even crazier...this is what i get now:
    -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
    Dim

  5. #5

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    ok this should work
    for(int* ia=both,* ib=both;ib<&both[MAX_LENGTH_BOTH];ib+=*ia!=*ib)*ib=*ia++;
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Almost there....it does remove the doubles...but when printing out the array using this code:
    for(j = 0; j <= (MAX_LENGTH_BOTH); j++)
    cout << both[j] << " ";

    It places the the doubles along with some other numbers at the end of the array...how would i resize the array based on how many doubles there were found.
    Going from something like this:
    -1 0 0 2 2 3 4 4 5 6 7
    To:
    -1 0 2 3 4 5 6 7

    Thanx for stickin with me kedaman...
    Dim

  7. #7

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    depends.
    if you treat both as a buffer and have say a terminator t, then t=ib, and you iterate like this:
    for(int*j=both;j<t;j++)
    cout << *j << " ";
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    k it seems to be working well...thank you for your help.
    Have a look at my other post...maybe you can help there also.

    Thanx,
    D!m
    Dim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width