Re: [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-03 13:37:55
|
I actually figured it out last night. Used a while loop with a flag that was set pos/neg depending on whether it found a duplicate and a for loop inside to read through the array. I knew about using break for switch, but didn't realize it could be used for while loops. Thanks! On Jan 3, 2008 8:26 AM, Wobien Doyer <wo...@pl...> wrote: > Look here http://www.cppreference.com/keywords/break.html (for instance). > > > ----- Original Message ----- > From: "Brian Weeden" <bri...@gm...> > To: "cpp" <dev...@li...> > Sent: Tuesday, January 01, 2008 11:20 PM > Subject: [Dev-C++] Searching and adding items to an array > > > >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 > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Microsoft > > Defy all challenges. Microsoft(R) Visual Studio 2005. > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > -- Brian Weeden |