Documente Academic
Documente Profesional
Documente Cultură
DATA STRUCTURES
AND
ALGORITHMS
Lecture Notes 5
Sequential Containers
Spring 2008
Mathematical abstraction
– Data abstraction
– Procedural abstraction
No implementation detail
Examples:
Integers, reals, booleans, lists, sets, graphs,
stacks, queues
together with their operations
Objects?
Operations ?
Had to slide
[2],[3] to [3],[4]
my_vector.insert(2, “Doc”);
Replacement is cheap
vector<Item_Type> some_Item_Types;
Item_Type nums[] = {5, 7, 2, 15};
for (size_t i = 0; i < 4; i++)
some_Item_Types.push_back(nums[i])
;
Item_Type sum = 0;
for (size_t i = 0; i < 4; i++) {
sum += some_Item_Types[i];
}
cout << "sum is " << sum << endl;
vector<Directory_Entry> the_directory;
Item_Type&
Item_Type& operator[](size_t index) {
// Verify that the index is legal.
if (index < 0 || index >= num_items)
num_items) {
throw std::out_of_range
("index to operator[] is out of
range");
}
return the_data[index];
the_data[index];
}
virtual ~vector<Item_Type>() {
delete[] the_data;
}