Thread: randomly remove elements

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    58

    randomly remove elements

    It seems more difficult than i thought...

    Ok,another question..Suppose that i have a set( vector) with n elements. How can i remove randomly let's say half of them??

    All the remove algorithms of C++ satisfy a criterion. I don't need one. Just randomly remove some elements.

    Thanx

  2. #2
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    a vector? Do a random_shuffle and then resize the vector to half its size.
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Oh, and I think you double posted Joan :}
    Double Helix STL

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    Yes, swgh..i didn't do it on purpose..

    sorry

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    I meant it light-heartedly, no need to apoligise, it is a mistake we all make once, somtimes this board is rather slow at processing a message
    Double Helix STL

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    Yes, exactly..i think that happend..
    Anyway, have u looked at my previous thread??

    Have u any idea?? anything would be helpful..if you don't understand sth from my description ask me.. :-)

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Randomly rearranging the elements in a vector
    By Signifier in forum C++ Programming
    Replies: 11
    Last Post: 08-01-2007, 12:21 PM
  2. how to remove even elements from list
    By lastrial in forum C Programming
    Replies: 3
    Last Post: 05-17-2007, 10:59 PM
  3. randomly remove elements
    By joan in forum C++ Programming
    Replies: 2
    Last Post: 12-06-2006, 12:22 PM
  4. Remove elements from array
    By Xentor in forum C++ Programming
    Replies: 8
    Last Post: 09-24-2006, 07:47 PM
  5. Replies: 5
    Last Post: 03-06-2006, 04:02 PM