Class Notes (1,100,000)
CA (630,000)
UW (20,000)
CS (1,000)
CS138 (10)
Lecture 6

CS138 Lecture Notes - Lecture 6: Type Safety, Bounds Checking, Call Stack


Department
Computer Science
Course Code
CS138
Professor
Michael Godfrey
Lecture
6

This preview shows half of the first page. to view the full 3 pages of the document.
Data Lecture 6
January 24, 2013
Vector Review
Vector is a CONTAINER data structure from C++ STD
o Like a C-style array except…
Generic and type-safe
Index bounds checking is possible
Can be resized on-the-fly
Either one element at a time or in chunks
o Other STL data structures:
Deque
List
Map
Set
Iterating through a vector
o Simple, normal, numerical approach
o Abstract, powerful but confusing way w/ STL iterators
Useful vector API
o v.at(i)
o v[i]
o v.size()
o v.capacity()
o v.empty()
o v.resize(int)
o v.reserve(int)
o v.push_back(..)
o v.pop_back(..)
o v.front()
o v.back()
o v.begin()
o v.end()
int main (...) {
vector <string> v;
v.push_back ("Reimer");
v.push_back ("Scrivens");
v.push_back ("Luongo");
for (int i=0;i<v.size();i++) {
cout<<v.at(i)<<endl;
}
v.pop_back();
v.pop_back();
string s=v.back();
cout<<s<<endl;
v.push_back("Palmateer");
for (vector<string>::const_iterator i=v.begin(); i!=v.end();i++) {
cout<<(*i)<<endl;
}
}
You're Reading a Preview

Unlock to view full version