another_vector; another_vector.push_back(10) if(example==another_vector) example.push_back(20); for(int y=0; y another_vector; another_vector.push_back(10) if(example==another_vector) example.push_back(20); for(int y=0; y

Presentation is loading. Please wait.

Presentation is loading. Please wait.

C++ Programming: chapter 10 – STL

Similar presentations


Presentation on theme: "C++ Programming: chapter 10 – STL"— Presentation transcript:

1 C++ Programming: chapter 10 – STL
2018, Spring Pusan National University Ki-Joune Li

2 Sample #include <iostream> #include <vector>
using namespace std; int main() { vector<int> example; example.push_back(3); example.push_back(10); example.push_back(33); for(int x=0; x<example.size(); x++) cout<<example[x]<<" "; if(!example.empty()) example.clear(); vector<int> another_vector; another_vector.push_back(10) if(example==another_vector) example.push_back(20); for(int y=0; y<example.size(); y++) cout<<example[y]<<" "; return 0; }

3 STL – Standard Template Library
Most C++ compilers provide a convenient container template. Data Types Useful Operations Based on Template Data Structure STL Name Library to #include Type Dynamic Array vector <vector> Sequence Linked List list <list> Stack stack <stack> Container Adapter Queue queue <queue> Binary Tree set <set> Associate Hash Table map <map> Max Heap priority_queue

4 What is container Contains elements (more than one)
Basic Operations on Container

5 Basic Operations Types Operation array vector list set Iterator begin
end Capacity size empty max_size Access front back operator[] X Modifier assign insert erase push_back pop_back clear

6 Sample – using Iterator
#include <iostream> #include <set> using namespace std; int main() { set<int> mySet; set<int>::iterator it; for(int i=0;i<5;i++) mySet.insert(it, i*10); for(it=mySet.begin(); it!=mySet.end();it++) cout<<*it<<" "; return 0; }


Download ppt "C++ Programming: chapter 10 – STL"

Similar presentations


Ads by Google