[Dev-C++] Searching and adding items to an array
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Brian W. <bri...@gm...> - 2008-01-01 22:20:39
|
I am writing a piece of code that is calculating values. That part is done and works. The problem is that as the code goes through the process it will generate duplicate answers. I want to filter those out and end up with just the solutions that are unique at the end of the whole process. What I was thinking of doing was writing the first solution to an array. Then with each additional solution a loop would read through the array checking to see if the new solution matches any of the existing solutions. If yes, exit. If no, it continues reading. When it reaches the end it would write the new solution to the end of the array since it didn't find a match. I am having trouble diagramming the logic flow and writing out the algorithm. I know I will need to keep one int counter of how many items are in the array and another for the loop counter that will get initialized to zero and iterated each time the loop is called. I'm not sure how to write the loop exit for a duplicate. Any help would be appreciated. Thanks! -- Brian Weeden |