Jump to content
  • Advertisement
Sign in to follow this  

Binary search.. or something

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an array of numbers, say: 1,2,3,7,7,7,8,9,9. From this array I want to make another array containing only the unique numbers (no duplicates), like so: 1,2,3,7,8,9. Simple, do something like this: for each number in array1 if not number exists in array2 then add number to array2 The problem is that I want it to be fairly fast and because of the array is huge looping through array2 to check if a number already exists gets slow. So I was thinking of sorting the arrays and do a binary search. Or is there some other clever way?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!