Now linkedlist use videoptr as the class use videoptr

Info iconThis 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: ld have a constructor, a destructor, We overloaded >> and << operators, and modification >> and << operators, routines which provide protection of vital data items. items. But we must weigh up the merits of such a step. But Is it overkill? Are there advantages? Is Or are we just complicating our program. Some programmers make node a class. Programming Some node Applied Now we have a very complicated LinkedList. Now LinkedList Use VideoPtr as the class Use VideoPtr It contains the functions we created for what is It actually a queue as well as the insertion and deletion functions of a true linked list. deletion LinkedList Vlist; Create a fresh video record for each new title, Create add its pointer to the database. add Deletions, of course, will then not free up a Deletions, VideoPtr's memory – the programmer will have VideoPtr memory the to call the destructor explicitly. to Applied Programming This would not normally be done. W e would have separate classes for each of the We ADTs. ADTs Applied Programming So we add But we'll continue on with our combined class. nodePtr tail; Let's see what improvements we can make on Let's the performance of the class. the to our private data. Adding items to the tail of the list required a full Adding traversal of the list. traversal Now the addition would be something like tail->next = newitem; >next newitem tail = newitem; tail newitem What if we know where the tail is? Easy additions. Applied Programming But we would still have trouble removing the last But item (we need to know the next-to-last node). item with some checks as to whether the list was with empty or head equalled tail. head equalled tail Applied Programming The new node structure would be struct node { int data; nodePtr prev, next; }; W hat if each node also contained a pointer to the What previous node? previous We'd have a doubly-linked list We'll use this symbol and many things would be easier. Applied Programming Head (curr) 1 2 3 6 0 4 0 5 Let's now insert 5. (newnode) All we have to do is adjust the pointers in All the usual three nodes. the Applied Programming Applied Programming Head (curr) 1 2 3 6 0 4 0...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online