Select element from Set randomly?

Discussion in 'C Programming' started by Davy, Aug 22, 2005.

  1. Davy

    Davy Guest

    Hi all,

    I have a Set contain several elements.

    I want to do:
    (1) Select one element from Set randomly;
    (2) Delete this element from Set;
    (3) If Set!=empty, goto(1);else, end.

    Is there any easy approach?

    Best regards,
    Davy
     
    Davy, Aug 22, 2005
    #1
    1. Advertisements

  2. There are easy approaches for sets of small cardinality (e.g., no
    bigger than a long); there are slightly more complex and time-consuming
    approaches for sets of larger fixed cardinality (e.g., vectors of long).
    Other than that, you pretty much get into linked list approaches
    (though some other approaches are practical if the set elements tend to
    "cluster".)
     
    Walter Roberson, Aug 22, 2005
    #2
    1. Advertisements

  3. Davy wrote on 22/08/05 :
    Either the algorithm is correct, and you just have to write the code
    yourself and post it here if you are stuck, either the algorithm is
    incorrect, and you cerainely don't want the help from a language group.

    Try
    --
    Emmanuel
    The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
    The C-library: http://www.dinkumware.com/refxc.html

    ..sig under repair
     
    Emmanuel Delahaye, Aug 22, 2005
    #3
  4. (supersedes <>)

    Davy wrote on 22/08/05 :
    Either the algorithm is correct, and you just have to write the code
    yourself and post it here if you are stuck, or the algorithm is
    incorrect, and you certainely don't want the help from a language
    group.

    Try

    --
    Emmanuel
    The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
    The C-library: http://www.dinkumware.com/refxc.html

    "Mal nommer les choses c'est ajouter du malheur au
    monde." -- Albert Camus.
     
    Emmanuel Delahaye, Aug 22, 2005
    #4
  5. What exactly to you mean when you say you have a Set? C has no
    built-in Set type, though there are a number of possible ways to
    represent sets.

    I think the C++ standard library has a Set type. If that's what
    you're using, you're in the wrong newsgroup; try comp.lang.c++.
     
    Keith Thompson, Aug 22, 2005
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.