O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Unidirectional Linked List with Structures for the Tape

One of the interesting capabilities offered by allocating structures from the heap is that you can use a pointer in the structure to link structures together into a list (called a linked list). For instance, you can create an indefinitely long list of aTapeElement structures by adding a member variable to aTapeElement that is a pointer to the next aTapeElement:

struct aTapeElement
{
   char Operator;
   float Operand;
   aTapeElement *NextElement;
} ;

Then you can link them together, like this:

 1: aTapeElement Tape; 2: aTapeElement SecondElement = new aTapeElement; 3: Tape.NextElement = SecondElement; 4: aTapeElement ThirdElement = new aTapeElement; 5: Tape.NextElement->NextElement = ThirdElement; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required