Thread: Array frustration

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

    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

    Further thoughts.

    Can you have a function that returns a pointer?

    Then I could have:

    *array=deletefrom(array, thisnode);

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


  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    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

    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, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10: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, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM