11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 14: Point and Stare at Objects 197The program then enters the while loop. If the pL pointer is not null, it pointsto some LinkableClass object. Control enters the loop, where the programcan then perform whatever operations it wants on the object pointed at by pL.The assignment pL = pL->pNext “moves” the pL pointer over to the nextkid in the list of objects. The program checks to see if pL is null, meaning thatwe’ve exhausted the list . . . I mean run out of kids, not exhausted all the kidsin the list.Hooking up with a LinkedListDataprogramThe LinkedListData program shown here implements a linked list of objectscontaining a person’s name. The program could easily contain whateverother data you might like, such as social security number, grade point average,height, weight, and bank account balance. I’ve limited the information tojust a name to keep the program as simple as possible.// LinkedListData - store data in a linked list of objects#include #include #include #include using namespace std;// NameDataSet - stores a person’s name (these objects// could easily store any other information// desired).class NameDataSet{public:char szName[128];};// the link to the next entry in the listNameDataSet* pNext;// the pointer to the first entry in the listNameDataSet* pHead = 0;// add - add a new member to the linked listvoid add(NameDataSet* pNDS){// point the current entry to the beginning of// the list...pNDS->pNext = pHead;// point the head pointer to the current entrypHead = pNDS;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!