--------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00150 Date: 04/08/98 From: JONATHAN DE BOYNE POLLARD Time: 01:54am \/To: DAVID NOON (Read 2 times) Subj: Bubble Becomes Zeppelin TT>> for (i1=0; i1> for (i2=i1; i2> if (elem[i1]>elem[i2]) { TT>> tmp = elem[i1]; TT>> elem[i1] = elem[i2]; TT>> elem[i2] = tmp; TT>> } TT>> } TT>> } DN> Ugh! That has even more iterations than genuine bubble sort. That *is* genine Bubble Sort. The only difference between that and the code that you are used to (which you posted) is the direction in which the array is processed. DN> This is _guaranteed_ to perform n**2 comparisons, even when the data DN> are already ordered. That is twice as slow as bubble sort's worse DN> case. Look again. Tom's code performs the standard N/2 comparisons. Notice the initial value of `i2' in the second `for' loop. JdeBP --- FleetStreet 1.19 NR * Origin: JdeBP's point, using Squish (2:440/4.3) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00151 Date: 04/08/98 From: JONATHAN DE BOYNE POLLARD Time: 02:01am \/To: GEORGE WHITE (Read 2 times) Subj: Aaargh! Bubble Sort *again* ! DN>>> for (i = n - 1; i > 0; --i) DN>>> for (j = 1; j <= i; ++j) DN>>> if (array[j-1] > array[j]) { /* swap j-1 with j */ } TT>> for (i1=0; i1> for (i2=i1; i2> if (elem[i1]>elem[i2]) { /* swap i2 with i1 */ } GW> It's not a "bubble sort", [...] Yes it is. I've elided the exchange code in both Tom's and David's code, which should make it clearer that they are, in essence, the same thing, merely processing the array in different directions. Tom's code is, in fact, closer to the "classic" Bubble Sort that most people think of, since it processes the array in the same direction as the final intended ordering. Given that David has previously bemoaned the fact that all that anyone seems to do in this echo is post Bubble Sort, I find it ironic and amusing that neither you nor he can actually recognise it when presented with it. Perhaps echo participants should be encouraged to post Bubble Sort *more often*, so that you two can sharpen your recognition skills. (-: JdeBP --- FleetStreet 1.19 NR * Origin: JdeBP's point, using Squish (2:440/4.3) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00152 Date: 04/24/98 From: SIMON AVERY Time: 01:42pm \/To: MICHAEL MCGAVIN (Read 2 times) Subj: Getting the command line "As if by magic, Michael McGavin appeared!" MM> Is there an easy way from within a program to get the complete command MM> line that was used to run the program? I'd like to be able to keep MM> all the whitespace and so on intact, which is why I can't just merge MM> together parameters passed through the main() function. I don't MM> really need the program filename itself, or any whitespace up to the MM> beginning of the first parameter. DOS 7 (Win95) sets the environment CMDLINE to pass the full command-line. Eg: C:\>SET ./. CMDLINE=edit \GOLDED\GOLDED.cfg That's not particularly portable though. AFAIK - the only decent way is to use argv[] from main, noting that there will be one space twixt each entry (or more - depends on what you expect to be passed to your program). (Waiting to be corrected. ') Ciao, Simon ... "Bother," said Michael, as he received a letter from the CSA. ... Tag-O-Matic V.13F Under Test... --- FMail/386 1.22 * Origin: WIN95_UK The echo for all Windows95 matters! (2:255/90) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00153 Date: 04/24/98 From: SIMON AVERY Time: 01:45pm \/To: NEIL HELLER (Read 2 times) Subj: TIME FOR A JOKE "Neil and Simon sitting in a tree..." NH> An item of humor can be seen by those having MSVC 5.0. Locate a file NH> named WINBASE.H and look at it in a text editor. There you'll find NH> the line: NH> //!!!MwH My Version NH> Either you'll laugh or wonder if the code that follows was finally NH> determined to be the best of all... Can't check, but here's another example from Turbo C/C++ V.3 for DOS. Online help - under section: sound() sound(int); /* Emits a 7-Hz tone for 10 seconds. True story: 7 Hz is the resonant frequency of a chicken's skull cavity. This was determined empirically in Australia, where a new factory generating 7-Hz tones was located too close to a chicken ranch: When the factory started up, all the chickens died. Your PC may not be able to emit a 7-Hz tone. */ Simon ... "Bother", said Neil, as Kanga sneezed in his honey pot. ... Tag-O-Matic V.13F (4377 Taglines) 901 13:46:54 Fri 24 Apr 1998 --- FMail/386 1.22 * Origin: My other computer is a PC as well. (2:255/90) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00154 Date: 04/24/98 From: KURT KUZBA Time: 11:45pm \/To: HERMAN SCHONFELD (Read 2 times) Subj: cprintf() & standards HS> And it was mainly for the use of ansi-colours, was it HS> not? That is why the c standard doesn't allow printf() to HS> output colours Actually, that is exactly backwards. :) printf() lacks color and cursor control because those things do not necessarily exist on the device being programmed, and so are not necessary to a standard implementation. Heck... my toaster doesn't even have a printer, much less a random access type display such as a crt or led screen. ( NOTE: This is a theoretical toaster with an embedded controller programmed in C. My REAL toaster employs springs and levers and a variable mechanical timer, and is badly in need of replacement, having lost the ability to adequately eject toasted objects and not being configured, in hardware, for the acceptance of thicker comestibles, such as bagels. ) cprintf() is a non-standard addition for platform specific compilers in which such things may be taken for granted. There is a sort of quasi-standard, or general consensus of the way things are done within the conio library, but nothing is guaranteed by the standard, and it does vary from compiler to compiler, sometimes enough to thoroughly vex a programmer attempting to change from, say, Turbo C, to MS C. The point is, that, beyond the standard, nothing is certain. Every compiler producer is at liberty to interpret their nonstandard functions in any way they find makes sense to them, and will best serve their customers. You can trace the logic of the various implementations easily enough, though it may give you a bit of a headache. Wherever cross-platform development is an issue, or code is to be shared with users of other compilers or OS's, then an effort should be made to either adhere to the standard or wrap the nonstandard calls in a secondary function, wherein the person using the source code may find all the nonstandard function calls, along with comments on their use and purpose so that they may either replace them or provide their own code to produce the same intended results. > ] Never ask for justice. Trust me... You won't like it........ --- * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00155 Date: 04/19/98 From: SIMON LAW Time: 05:33am \/To: DARIN MCBRIDE (Read 2 times) Subj: Learning C++ Darin McBride suddenly realized that he had nothing to do with Simon Law or "Learning C++." Hi Darin McBride, DM> main() DM> { DM> /* code */ DM> return 0; DM> } DM> is perfectly legal, if somewhat archaic. It's when it becomes "void DM> main" that we have problems. :-) SL> Wait a second. Is encouraging the use of this because you SL> don't have to specify a type a good thing? DM> I said 'archaic'. :-) I guess I should have pointed out that it may DM> not be supported in the next version of ANSI C. Oh good. It made me uncomfortable, seeing no type. Yours Sincerely, Simon Law Internet: simon.law@ablelink.org FidoNet: 1:250/518 ... Time you enjoy wasting is not necessarily wasted time. --- * Origin: Tanktalus' Tower BBS (1:250/102) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00156 Date: 04/22/98 From: BILL BIRRELL Time: 08:51am \/To: CARLTON WALTERS (Read 2 times) Subj: could someone give an example of how to Hey Carlton, > write a program that calculate the factorial of a > entered integer. > I did this before but I forget. > thanks. C is not particularly suitable for number crunching, and factorials have no upper bound, so a microprocessor program is pretty limited in what it can achieve before running out of memory, unless you wish to go to the trouble of writing a multipass disk based program. Even then you will run out of disk space before you run out of factorials. :-) This will give approximate factorials up to about !170. After that you are on your own. :-) /* PROGRAM FACT */ #include #include int main(int argc, char *argv[]) { long i, number; double result; char istring[32]; puts("\nPlease enter a 2-digit number >"); gets(istring); number=atol(istring); result = 1.0; for( i=1L; i <= number; i++) result *= i; printf("\nFactorial of %ld is %g",number,result); return (0); } Best wishes, Bill. --- * Origin: Meerkats Anonymous (2:2504/200) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00157 Date: 04/22/98 From: BILL BIRRELL Time: 08:52am \/To: ELIJAH HUYNH (Read 2 times) Subj: Nested loop > You forgot that I'm a beginner. The exercise asked for > nested loop using for loop. Oh ... you didn't mention the 'for' part before. bb. --- * Origin: Meerkats Anonymous (2:2504/200) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00158 Date: 04/22/98 From: BILL BIRRELL Time: 08:56am \/To: DARIN MCBRIDE (Read 2 times) Subj: Event Handler Darin, To Herman Schonfeld you wrote:- > I always am. [right] and then:- > What does "stdin" mean? It means two basic things: > - It can be redirected externally to the program > - If not redirected, output goes to "the screen". Eh????? stdin??? stdIN???? . bb. --- * Origin: Meerkats Anonymous (2:2504/200) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F5G00159 Date: 04/23/98 From: BILL BIRRELL Time: 08:03am \/To: CARLTON WALTERS (Read 2 times) Subj: !n A crib from a fortran program:- /* PROGRAM FACT */ #include #include int main(argc, argv) int argc; char *argv[]; { unsigned int i, number; long double result; char istring[32]; puts("\nPlease enter a number up to 1754 :"); gets(istring); number=atol(istring); result = 1.0; for( i=1; i <= number; i++) result *= i; printf("\n!%u is %LG",number,result); return (0); } bb. --- * Origin: Meerkats Anonymous (2:2504/200)