CS 112
Lecture 17
Linked Lists
Reading for this topic
Textbook, Ch. 7. But careful, the linked list ADT in the book may be slightly
different from the one I will be discussing in class.
-
list applet.
- Dynamic memory allocation: when having an upper bound on the allocated
memory is not good (e.g. for stacks and queues).
When space is allocated and deallocated in an
unpredictable fashion (as opposed to stacks and queues).
- Linked lists: motivation, definition, operations: insert, delete, empty.
- Informally drawing lists. Box representation.
- Implementing a node of a list in C/C++: struct and typedef; pointers; arrow
notation.
Example and
execution.
- Allocating a new node in C/C++: the new operator.
- Discussion of subtleties in implementing list operations. The
head of a list.
- Implementation of the operations on lists: insert,
delete, empty, etc. Implementation of the Linked List ADT.
example1.cpp.
We did up to here. To be continued next Th.
For practicind the
ideas discussed in class today, look at an old
exam. Do problems 3, 5 and 6 from the
exam. Discuss them with the TA in class on Tuesday, and be ready
to ask me questions on Thursday.
- Allocating space dynamically. The new and
delete operators in C++.
Look at new example2.cpp and execute it
(typescript), see how new and delete
work. Careful with their use.
- The Linked List abstract data type.
List applet.
- Hwk: C++ class for lists.
Next week: applications of lists, and: pointers, pointers, pointers...
Tuesday will be all lab work, to be done in class and submitted by 10:20.
Ileana Streinu