CS304: Lecture 14 - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

CS304: Lecture 14

Description:

With the STL, C not only encourages reusable software, ... Multimap. Adapters. Stack. Queue. Priority Queue. STOP! Discussion of final. Course evaluations ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 12
Provided by: matthe49
Category:

less

Transcript and Presenter's Notes

Title: CS304: Lecture 14


1
CS304 Lecture 14
  • The Standard Template Library
  • Deitel, Ch. 23
  • http//www.cis.uab.edu/cs304

2
Why the STL?
  • Cs main design philosophy centers around
    software reuse
  • With the STL, C not only encourages reusable
    software, but also provides reusable software
  • The STL, through use of templates, gives the user
    a set of data structures, algorithms, and
    iterators to create type-safe, fool-proof
    containers.

3
The Data Structures
  • Examples in this category include many of the
    structures you are familiar with
  • Vector (array)
  • List (linked list)
  • Deque (Double Ended Queue)
  • Much common functionality to be had

4
Iterators
  • Iterators are glorified, safe pointers
  • Type Safety
  • Bounds safety
  • Yet, arithmatic is still allowed!
  • Convenient, expressive when combined with
    algorithms
  • Many types, depending on your needs!

5
Algorithms
  • Examples of some algorithms available
  • Sort
  • Reverse
  • Copy
  • Remove
  • Unique

6
Sequence Containers -- Vector
  • An array-based container
  • Dynamically resizes, assignable, optional bounds
    checking (using at)
  • Includes functions for insertion at any position
    of the vector
  • Due to the array-ness of the vector, insertion is
    efficient only at the end

7
Sample Vector Functions
  • Front Returns an iterator that points to the
    first element of the vector
  • Back Returns an iterator that points to the
    last element of the vector
  • Reference an element within a vector
  • Push_back Insert an element at the end of the
    vector
  • Size Returns the size of a vector

8
Iterator Example on a Vector
  • include ltvectorgt
  • include ltiostreamgt
  • using namespace std
  • int main()
  • vectorltintgt v
  • vectorltintgtconst_iterator cIter
  • for (int i 0 i lt 100 i)
  • v.push_back(i)
  • for (cIter v.begin() cIter ! v.end()
    cIter)
  • cout ltlt cIter ltlt ' '

9
Using an algorithm on a vector
  • include ltcstdlibgt
  • include ltvectorgt
  • include ltiostreamgt
  • using namespace std
  • int main()
  • vectorltintgt v
  • for (int i 0 i lt 100 i)
  • v.push_back(rand())
  • sort(v.begin(), v.end())
  • for (int i 0 i lt v.size() i)
  • cout ltlt vi ltlt endl

10
Other Types of Containers
  • Associative
  • Set
  • Multiset
  • Map
  • Multimap
  • Adapters
  • Stack
  • Queue
  • Priority Queue

11
STOP!
  • Discussion of final
  • Course evaluations
Write a Comment
User Comments (0)
About PowerShow.com