FloWo3 said:
how do you create (design) algorithms.
I'm talking about thinking about it and come to an idea.
Examine the problem in small steps. Break down each little piece into
baby steps.
Contrary to other posts, I don't use paper and pen unless I'm trying to
visualize the actions of a loop of something like that.
I start in with an editor (not necessarily an IDE, Notepad works fine)
and start by just typing in comments of the steps I think I need, like
this:
---------------------------------------
// allocate variables
// open input file
// read data from file (into struct, line at a time, or whatever)
---------------------------------------
As I'm working I fill in things I find I need, like this:
---------------------------------------
// allocate variables
// loop counter, if necc.
// line buffer
// struct for file data, or alloc as needed
// open input file
// loop to read data from file into struct one line at a time
// read a line into line buffer
// parse line buffer into struct
// close file
// do something with data struct
// deallocate as necc.
---------------------------------------
The above is more C-like than C++, but you get the idea.
I try get the full problem scoped out before writing any real code, and
if some step is very complicated I just open another notepad for that
function or class. Eventually, I find things that I can fill in as real
code, but I try to resist that as long as possible.
Some will say that you have to use paper for this process, but editors
work for me. YMMV. On the plus side of this method you end up with fully
commented code at the end. And the comments are sometimes more correct,
since they change as the design is fleshed out - before the code is
written.