We Continue Our Data Structure Journey!
So far we have seen:
- Singly linked lists
- O(1) for insert, O(n) for remove.
- A few special cases in insert and remove.
- Doubly linked lists
- O(1) insert and remove.
- But we have many special cases.
- Circular doubly linked list with sentinel
- O(1) insert and remove.
- No special cases: the code is very clean.
Lets try a list of students by grade
Operations
- Insert a new student and score.
- Remove a student.
- Update a student's score.
- Print all scores.
- Print one student's score.
- Load names and scores from a file.
- Save names and scores to a file.
See Demo sentinelDLLstream.h
Some things to note are:
- element::print takes an ostream by reference.
- ostream can be cout, cerr, or any output file.
- Overloaded list::print, one version takes an ostream, other assumes cout.
See Demo sentinelDLLstream.cpp
Some things to note are:
- element::print uses ostream.
- list::print without ostream calls list::print with cout.
- list::print with ostream just uses stream name in place of cout.
See Demo Scores.cpp
- Many member functions use the list member functions.
- Can run with the debugger and view the array as an array and open up
the contents of each linked list in the array.
Abstract Data Types
Abstarct data types are data structures that are defined by their
instructions. The users of the ADT's need not and should not know
how they are implemented, though it is ok to have a
"mental model" of how they work. For instance:
Stack
Operations:
push
pop
isEmpty
print
And as a user, this is all we need to know. We do not need to show concern
about how these operations are implemented. An example of a stack would be:
Make sure that you look into the demos:
- ADT.h - stack
- ADTsentinelDLL.h
- ADTsentinelDLL.cpp
- Added firstOf() and getCurrentString()
- ADT.cpp - stack
- stackTest.cpp
To Index
Previous