Help with code, please. C++ Programmer's Notebook 2nd Edition

I am studying from a book : C++ Programmer's Notebook 2nd Edition by Jim Keough and John Shapley Gray.

I am having a problem with pages 438 - 439 : Using a Linked List Queue.

If anyone has this great book could you help me please?


I can't understand the line near the bottom of the do loop:

if ( ++count > n/2-1 ) break;

also right above it why are the integers being swapped?

Thank you,
Josheir
Last edited on
Hi,

You might get more help if you post the code you are having trouble with - the majority probably won't have your book to look at.

Cheers :+)
I'm trying to get permission to republish. I was hoping maybe I'd get lucky!

Josheir
near the bottom of the do loop
if ( ++count > n/2-1 ) break;

Exit loop when the count gets too big?
(The loop probably has some other quit condition too, but occasionally one needs more exit points.)
I seriously doubt the author will care if you share a code snippet you have a question about from a 15 year old book on a programming forum (which should constitute fair use,) particularly considering the code used to be hosted online (although the link appears to be broken now.)
Yes exit the loop if the count gets to big, however n increments in a prior loop and n is the number of times it incremented and another operand/operator is added to a queue.

The thing is n can be any number 1,2,3,4,... etc. If n is an odd number there will be a .5 truncated. i.e. 3/2-1 = 0.

So I don't know perhaps there was supposed to be another n variable somewhere, not certain?

if n is 4 expression is 1 if n is 6 expression is 2. I just don't understand the relationship between count and n.

The only other info is in the description that there is one more operand than there is operators.

The loop that iterates n is reading one character at a time in PREFIX where the character is either a operator/operand.

The objective is to turn PREFIX into INFIX.

Where prefix has the operators in front of the operands and infix is typical notation using parenthesis.

Well the program is very light font and I'll try to find a way to attach it.

Really this should maybe be sufficent because these two places are the only places that mention the variable n and count other than intializations.

I know it's not a whole program, but perhaps some people like solving puzzles :)

Josheir
Last edited on
Topic archived. No new replies allowed.