CPS 6, Ramm - Summer Semester I - 6/7/01 #15

8. Arrays, Data, & Random Access

type is any with default (parameterless) constructor

  • Vector Initialization

  • Character Frequencies in Classical Cryptography


  • Vector Parameters
    letters.cpp

  • A Draft Word in Context Program
    context.cpp

  • Redesigning a Word in Context Program
    Redesign in Classroom
    context2.cpp

  • What if File is Too Large?

  • How to Solve Problem Without Vectors?

  • Translating Characters to Morse Code (char to string)
    Translate Table
    morse.cpp
    "CryptoQuotes" (char to char)
    transl.cpp

  • Size and Capacity: "The Partially Filled Array"
    • Classical: Programmer keeps explicit track of each
      • when passing vector argument, also pass size
    • tvector class: Class keeps explicit track of each
      • requires use of special member functions

  • Using push_back
    • Start with empty vector (capacity = 0)
    • Use push_back to add elements
    • Class does the rest
    • Do not need to pass size a paramter!

  • A Simple Information Storage/Retrieval System
    • Concepts
      • Store lines from file in vector
      • Retrieve lines by matching substrings
      • Like UNIX grep program
    • getinfo.cpp

  • Improving the Storage/Retrieval System

  • WordList Class
    • List of Unique Words
    • Update with next word
      • Search for previous
    • Print Unique List
    • allword3.cpp

  • Binary Search
    • Telephone Book Analogy
      • Eliminate half each time
    • 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