CS 112 - Week 10 Lecture 1 - 2022-10-25
TODAY WE WILL
* announcements
* start intro to LINKED LISTS
* prep for next class
-----
* Visiting Speaker - Thursday, October 27,
4:30 - 5:30 pm, FH 125
Dr. Dipak Ghosal, UC Davis CS Chair -
Next Generation Data Centers
* Exam 2 - this Friday, during lab!
* submit any final improved pieces from HWs 4-7
by 11:59 pm TONIGHT,
so example solutions can hopefully become visible
by 12:01 am
* if interested in Exam 2 Study Guide bonus,
submit that photo/scan of your HANDWRITTEN Exam 2
study sheet by 9:00 am on FRIDAY
=====
intro to LINKED LISTS!
=====
* reading: Savitch, Chapter 13 -- BUT!!! note that we are approaching
this DIFFERENTLY than Savitch, so keep that in mind
* linked lists are another of "classic" data structures,
and, like arrays, (and sometimes along WITH arrays),
are used in IMPLEMENTING other data structures;
* like an array, a linked list is a collection of data;
* tend to allocate space for its elements as you add
each element;
* the elements are not as directly accessible as those
in an array
BUT, it is easier to insert and delete from the
"middle" of a linked list than from the "middle" of
an array...
* there are interesting TRADEOFFS between these
when you are figuring out which to use for some task;
* so: array elements are located right next to each other
linked list elements are not -- they can be anywhere!
SO in the "classic" implementation of a linked list,
each element includes where to find the next element;
=====
quick aside: typedef
=====
* Savitch, Ch. 9, Section 9.1
You can assign a NAME to a type definition, and use
that type name to declare variables, method headers, etc.
C++ keyword typedef makes this possible:
typedef known_type new_type_name;
typedef int NodeDataType;
...we'll use this in our Node class...
* now that I have a Node class --
ideally I'd now make a List class (or a Stack class, or a Queue
class, etc.!)
BUT let's start with just some functions that would be
useful on a not-yet-class linked list
* we'll say: a linked list has a head pointer,
a pointer to its first node
Node *head_ptr;
* empty list? head_ptr should be:
head_ptr = NULL;
* let's make a set of linked list functions,
with headers in linked-list-functs.h
and implementations in linked-list-functs.cpp