This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ld have a constructor, a destructor,
overloaded >> and << operators, and modification
>> and << operators,
routines which provide protection of vital data
But we must weigh up the merits of such a step.
Is it overkill? Are there advantages?
Or are we just complicating our program.
Some programmers make node a class. Programming
Applied Now we have a very complicated LinkedList.
LinkedList Use VideoPtr as the class
Use VideoPtr It contains the functions we created for what is
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,
add its pointer to the database.
Deletions, of course, will then not free up a
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
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
the performance of the class.
the to our private data. Adding items to the tail of the list required a full
traversal of the list.
traversal Now the addition would be something like
tail->next = newitem;
tail = newitem;
newitem What if we know where the tail is?
Applied Programming But we would still have trouble removing the last
item (we need to know the next-to-last node).
item with some checks as to whether the list was
empty or head equalled tail.
head equalled tail
Applied Programming The new node structure would be
nodePtr prev, next;
}; W hat if each node also contained a pointer to the
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
the usual three nodes.
the Applied Programming Applied Programming Head (curr) 1 2 3 6
0 4 0...
View Full Document
- Spring '14
- Computer Science