User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 391,706 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,292 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:

Array without twice the same number?

Join Date: Oct 2004
Location: Lahore
Posts: 10
Reputation: Ejaz is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Ejaz's Avatar
Ejaz Ejaz is offline Offline
Newbie Poster

Re: Array without twice the same number?

  #2  
Oct 22nd, 2004
One solution can be, before inserting the new no. in the array, scan the array (iterate through it), to see whether the no. is already in the array or not, if not, insert it and yes, loop again.

You can either iterate by simple loop or if you manage to create the array in sorted order, then you can use binary search (which is much faster) to serve the purpose.

If you can use STL, then you can use vector and find algorithm, which can make your life much easy.
Regards,

Ejaz.
Reply With Quote  
All times are GMT -4. The time now is 2:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC