Node int linkedlistnext int tmp current data current

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: erator() void LinkedList::SetIterator { current = head; } serves that purpose. W e probably should set current to 0 iin the We current to n constructor to indicate a non-set iterator, as it will constructor set iterator as be when the end is reached. be Applied Programming How about Applied Programming The next function returns the data at the current The node of the list and moves current on to the next node. node. int LinkedList::Next() { int tmp = current->data; current = current->next; current current return tmp; return tmp } It will fail if current iis 0, so there should be a It current s so check. check. Applied Programming Here is how an iterator is used: Here iterator bool LinkedList::More() { return (current != 0); } LinkedList list; int data; // There is a problem. W hat if the user adds or deletes a node while What iterating? iterating? Such changes should be locked out. Or current should be reset to ?. Or current should // Applied Programming set up the list list.SetIterator(); while(list.More()) { data = list.Next(); data list.Next process data } Applied Programming W e can actually use iterators to perform We iterators to additions and deletions. additions void InsertBeforeCurrent(const int&); void InsertBeforeCurrent(const int DeleteCurrent(); W e would need the extra member data variable We previous for these extra actions. previous Iteration could then continue. Recall: const int MAXTITLE = 40; const int const int MAXCATEGORY = 10; const int struct Video { char Title[MAXTITLE+1]; long BarCode; long BarCode short RunTime; short RunTime char Category[MAXCATEGORY+1]; short NumCopies; short NumCopies }; LinkedList VideoDB; Applied Programming Applied Programming W hy can't Video be a class? Why Video We now provide int ListDataCmp(const Video& V1, const Video& V2); to indicate the alphabetical order of the Title. to Title. Everything else is as described in our general Everything LinkedList. LinkedList In fact we can go one step further. Applied Programming A further possibility. W e cou...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern