Results 11 to 16 of 16
Thread: C++ This time!
-
11-03-09, 08:09 AM #11
Re: C++ This time!
Yeah, do not give up if you got time.
You just gave me another idea of a method that would require less operations, but still recursion.
Two arrays of references (pointers). One is initalized to all null references. The other is initialized to reference each element in your vector.
As you generate random indices you do the following.
1) take reference of element[random] and put it in element[0].
2) take whatever reference was in element[0], and put it in element[random] in the other array (the blank one).
3) null out element[random]
Now as you iterate through, if you encounter an element[random] that is null you know you already chose that element. Recurse to repeat the operation when this happens.
Once you have moved x% of elements to the blank pointer array, you now fill all the null spots with whatever is left in the original array. Pass that back out.
-
-
- Join Date
- 11-26-06
- Location
- Anywhere you want to be.
- Posts
- 3,946
- Post Thanks / Like
- Blog Entries
- 1
11-03-09, 03:03 PM #13Re: C++ This time!
Originally Posted by HeavyG
What are you saying , we need a programming sub forum or something......
-
-
-
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks