Select element from Set randomly?

D

Davy

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
 
W

Walter Roberson

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?

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".)
 
E

Emmanuel Delahaye

Davy wrote on 22/08/05 :
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?

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
 
E

Emmanuel Delahaye

(supersedes <[email protected]>)

Davy wrote on 22/08/05 :
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?

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.
 
K

Keith Thompson

Davy said:
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.

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++.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top