Array frustration

This is a discussion on Array frustration within the C Programming forums, part of the General Programming Boards category; I'm really not sure how to approach this problem anymore. I'm going to type it out really pedantically to try ...

  1. #1
    Not bad at Crack Attack!
    Join Date
    Aug 2003
    Posts
    45

    Array frustration

    I'm really not sure how to approach this problem anymore.
    I'm going to type it out really pedantically to try and figure it out for myself - but any suggestions greatfully received.

    PROBLEM: Pick p numbers from n (n>>p) with no repetition.

    SOLUTION: create choices[p] and delete p[i] from the source array at the ith step.

    Easy, surely?

    I have the feeling that I need to think a little more laterally than I am at the moment. Currently, I have a subfunction that deletes an element from the array - which requires wiping an array created in main, making a new one with the same name obviously and then returning to main pretending that nothing has happened. (It's a void function) - I think this is the main problem with my current approach.

  2. #2
    Not bad at Crack Attack!
    Join Date
    Aug 2003
    Posts
    45

    Further thoughts.

    Can you have a function that returns a pointer?

    Then I could have:

    [CODE]
    *array=deletefrom(array, thisnode);
    [\CODE]

    array would get chopped up within the deletefrom function but it would be okay because you are effectively returning the array?

    hmmmm

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    hmm... what about having a way to determine if a number was picked, e.g. a separate array of indices, or a search made on the array?

  4. #4
    Not bad at Crack Attack!
    Join Date
    Aug 2003
    Posts
    45
    Thankyou.

    A simple idea but so effective. I should be able to make everything work from here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21