|
From: Per W. <pw...@ia...> - 2004-02-13 18:39:29
|
My second algorithm have the problem that it varies the probability of selecting a line with the length of the line. However, it has the advantage that it can process any size of file in constant time with constant memory consumption. Sometimes this is an important trade-off. /Per W On Fri, 13 Feb 2004 wa...@wa... wrote: > On 13 Feb 2004 at 18:10, Per Westermark wrote: > > > Oooh. Lots of code, and memory intensive if the file is really big. > > Well, everything's a tradeoff. If you get intensive with the memory, > you get the benefit of the code being a little faster. With the > algorithm I wrote up, you only have to read the file once and then > you can access the line you want immediately. With your first > algorithm, you've got to read the same information over and over. > > And I don't think my version would be bigger code-wise. > > Your second algorithm is making the assumption that the random number > is generated by the program and can refer to a random place in the > file as opposed to a random line in the file. I was making the > assumption that the random number would be supplied by the user. > After re-reading the OP's question, I think you're right. > > > No need to fight with Windows API unless speed is > > absolutely imperative, i.e. normal c/c++ file operations are > > quire ok to use. > > I didn't know that Windows had separate file operations per se. I > was assuming he'd use the regular file streams. > > But I'm not sure if the point of the assignment is to teach them how > to read text files or use Windows. If you'll notice, the OP said > specifically that the program was to use the Windows API and that > refreshes should be done by hitting a button. That looks like the > point is more how to write Windows code than to read text files. > > Watson (the pencil neck) Davis > > > > ------------------------------------------------------- > SF.Net is sponsored by: Speed Start Your Linux Apps Now. > Build and deploy apps & Web services for Linux with > a free DVD software kit from IBM. Click Now! > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click > _______________________________________________ > 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 > |