CPS 6, Ramm - Spring 2000 - 3/10/00 #22
Chap 8. Arrays, Data, & Random Access
- Modify WordList Class
- Use the new member functions
- .reserve(), .push-back()
- .capacity(), .size()
-
allword3.cpp
- Binary Search
- Telephone Book Analogy
- Requires Sorted Lists
-
| list size | binary search | sequential search
|
| 1 | 1 | 1
|
| 10 | 4 | 10
|
| 1,000 | 11 | 1000
|
| 5,000 | 14 | 5000
|
| 100,000 | 18 | 100,000
|
| 1,000,000 | 21 | 1,000,000
|
-
binsearch
- Keeping a Sorted List
- Deletion
- From a sorted list?
- .pop_back()
- Arrays (built-in)
- Overview
- Syntax
- Size known at compile time.
- Initializaton
- No range checks
- Parameters
- Assignment
- Keeping track of size
- Will not use
Chap 9. Strings, Streams, and Operators
- Strings are Vectors of Characters
- Use indexing operator [] to get char
- Don't get out of range!
- Can both access and change characters
- Can also access characters (as strings) with .substr(pos,len)
- Reverse Order of Characters in a String
- Convert Characters to Strings
- Strings with one element are not characters.
- Can convert char to string using string(char)
-
capital.cpp
- String Streams
- Read from String as if it were a file.
- Use getline() to
read line from file stream or cin
- Use istrstream to
read info from string.
- Daily Sales Ticket Processing