multimaps
Download
Skip this Video
Download Presentation
Multimaps

Loading in 2 Seconds...

play fullscreen
1 / 19

Multimaps - PowerPoint PPT Presentation


  • 112 Views
  • Uploaded on

Multimaps. Resources -- web. For each new class, browse its methods These sites are richly linked, and contain indexes, examples, documents and other resources http://www.sgi.com/tech/stl/ http://www.cs.rpi.edu/projects/STL/htdocs/stl.html. Resources -- texts.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Multimaps' - emlyn


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
resources web
Resources -- web
  • For each new class, browse its methods
  • These sites are richly linked, and contain indexes, examples, documents and other resources

http://www.sgi.com/tech/stl/http://www.cs.rpi.edu/projects/STL/htdocs/stl.html

resources texts
Resources -- texts
  • Josuttis, The C++ Standard Library
  • Austern, Generic Programming and the STL
  • Musser, STL Tutorial and Reference Guide
  • Schildt, STL Programming
  • Skansholm, C++ from the Beginning
slide4
pair
  • The STL includes ‘utilities’
  • Class pair treats two values as single unit
  • Members: first, second (both public)
  • Convenience function: make_pair
pair example
Pair example

#include

string s1("cat");

string s2("catnip");

pair favorite(make_pair(s1, s2));

fstream
  • Descendent class of ios and iostream
  • Permits reading and writing files as streams, using << and >>

#include

ifstream inFile(“fileName”); // read

ofstream inFile(“fileName”); // write

fstream inFile(“fileName”); // r/w

nested containers
Nested containers
  • A container can hold any data type
  • A container can hold another container
  • Example:

#include

#include

#include

using namespace std;

Vector< list > vls;

algorithms
Algorithms
  • is an example of generic programming
  • Object-oriented binds methods + members -- generic applies algorithms to many data types
  • Examples: sort, swap
slide9
Sort
  • sort requires random access, <
  • Sort works on a range

#include

sort(begin, end);

sort(begin, end, op);

stable_sort(begin, end);

and the result is
And the result is ..

string s(“tictoc”);

sort( s.begin(), s.end() );

sort( &s[0], &s[2] );

slide11
Swap
  • Swap acts by manipulating pointers
  • Swap may replace a = b; if b is no longer needed
  • Swap is more efficient than assignment (constant regardless of size of data structure)
associative containers
Associative containers
  • Sets
  • Multisets
  • Maps
  • Multimaps
map v multimap
Map v multimap
  • Both store {key, value} pairs
  • In both, key and value may be of any type
  • In both, values may be duplicated
  • In map, key must be unique
  • In multimap, you may have duplicate keys
slide14
Map

“dog”“woof”

“cat”“meow”

multimap
Multimap

“joe”“850-1234”

“joe”“[email protected]

multimap constructors
Multimap constructors

map c; // empty map

map c(op); // empty map w/ using op to sort

map c1(c2); // copy constructor

map c(beg, end); // initialize with beg-end range

map c(beg, end, op); // init and specify op

multimap comparisons
Multimap comparisons

c.size(); // number of elements

c.empty(); // short for size == 0

c1 == c2; // these boolean operators do what

c1 != c2; // you’d expect

c1 < c2;

c1 > c2;

c1 >= c2;

c1 <= c2;

key ranges
Key ranges

count(key); // # elems w/ this key

find(key); // iter to 1st inst of key, or end()

lower_bound(k); // iter to 1st key >= k

upper_bound(k); // iter to last key >= k

equal_range(k); // iters to first and last // key == k

insertion deletion
Insertion/deletion

c.insert(pair); // return pos of inserted elem

Easiest way to insert is to use make_pair:

m.insert(make_pair(key, val));

m.erase(pos);

m.erase(begin, end);

m.clear();