0% found this document useful (0 votes)
8 views3 pages

dsa notes all

Uploaded by

techrangers2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

dsa notes all

Uploaded by

techrangers2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

C++ (# include <bits/stdc++.

h>)

1. STL (standard Template library)


 Collection of template classes (stack, queue, vector) and function (sort (), min (), max ());
 Offer high performance and reusable readymade components
 Key Components -
i. Container – storing data, ex- vector list map set
ii. Algorithm – functions ex – sort()
iii. Functions – ex – for(int i:vector) – akka for_each
iv. Iterators – a object that points to element in
2. Pairs – can store different type of data
 pair <int,int> student;
 Student.first = “Sanskar”;
 Student.second = “22”;
 pair<string,int> details(){}
3. Vector – dynamic array resize at 2^n n=0,1,2,…
 vector<int> v;
 excessing - v[0]; v.at(0)
 v.size();
 v.push_back(x);
 v.pop_back();
 v.front();
 v.back();
 vector<int>::iterator it = v.begin();
 auto it = v.begin(); for excessing *it
 for (auto i = v.begin(); i < v.end(); i++){cout << " " << *i;}
 for(int i=0;i<v.size();i++){ cout<<i ;}
 for each - for (auto i : v){cout <<" "<< i;}
 erase – v.erase(v.begin() +1) // erase second element
 insert - v.insert(position(iterator form),value);
 swap – v.swap(v1,v2);
 remove all elements from vector – v.clear();
4. List –
 Doubly linked list (insert & delete from both end)
 non contiguous memory allocation
 traversal – slower than vector ,
 insertion deletion – faster than vector
 list<int> ls;
 ls.push_front();
 ls.emplace_front();
5. deque
 deque<int> dq;
 in scenarios where elements are frequently added or removed from both ends.
6. Stack
 stack<int> s;
 s.push(x)
 s.pop()
 s.top()
 s.size()
 s.swap(s2)
 s.empty()
7. Queue
 queue <int> q;
 q.push(x);
 q.pop()
 q.front();
 q.size();
 q.swap(q2);
 q.empty();
8. Set – unique & sorted
 set<int> s;
 s.insert(x);
 s.erase(x);
 s.find(x); returns iterator if found or end() if not found
 s.lower_bound(20) ; barabar ya bada
 s.upper_bound(20); us se bad
9. multiset – not unique but sorted
 multiset<int> ms;
 ms.insert(10);
 ms.erase(x); // remove all x
10. unordered set- unique but unsorted
 unordered_set<int> us;
 us.insert(10);
 s.erase(x);
 s.find(x); returns iterator if found or end() if not found
11. Map - key-value & sorted based on key
 map<int, string> m;
 m.insert({1, "one"});
 m.emplace(2, "two"); // Emplaces a key-value pair
 m[3] = "three"; // Assignment
 m.find(x);

functions and algo

1. sort(v.begin(),v.end());
2. accumulate(v.begin(),v.end(),initial sum); // sum of all elements in vector
3. count(v.begin(),v.end() , value to be count)
4. find(v.begin(),v.end(),value to be found)
5. next_permutation(v.begin(), v.end());
6. auto it = max_element(v.begin(), v.end());
cout << "Max Element: " << *it;
7. reverse(v.begin(),v.end());
8. pow(base,exp)
9.

You might also like