Level 1 STL – Linear DS fb.com/acmicpcfcicu
Static Arrays Creating 1D, 2D, ND Static Arrays. Accessing Time. Traversing a static array with N dimensions. 1D Array Manipulation. 2D Array Manipulation.
Dynamically-Resizable Arrays (Vectors) Creating Vector vector v; vector v(10); //create vector with initial size 10, and initialize it by zeros Important Functions: – push_back(), pop_back(), size(), insert() How resizing is done internally + resizing complexity.
Pairs pair contestant; contestant.first = 6; contestant.second = 234; cout << contestant.first << “ “ << contestant.second << endl; contestant = make_pair(6, 234); contestant = {6, 234}; // C++ 11
Iterators vector v; v.push_back(10); v.push_back(20); vector ::iterator it = v.begin(); //pointing to the first element cout << *it << endl; // 10 it = find(v.begin(), v.end(), 20); if(it == v.end()){ cout << “10 Not found”; }else{ v.erase(it); cout << “New vector size is: “ << v.size() << endl; }
Algorithm sort(v.begin(), v.end()); sort(v.begin(), v.end(), sort_contestants); reverse(v.begin(), v.end()); find(v.begin(), v.end(), 10);
Stacks
Last In First Out Creating Stack stack s; Important Functions: – push(), top(), pop(), size()
Queues
First In First Out Creating Queue queue q; Important functions and their complexities. – push(), front(), pop(), size()
Dequeues Creating Dequeue Important functions and their complexities. – front(), back(), push_front(), push_back(), pop_front(), pop_back()
Bit Manipulation Bitwise operations: |, &, ^, ~, >>, << setBit clearBit getBit toggleBit