Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions STL 2.0/MAPS/basics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
-------------- ORDERED MAPS -----------------
Time Complexity : O(log(n))
*/

#include<bits/stdc++.h>
using namespace std;

void print(map<int,string> &m){
cout<<"Size: "<<m.size()<<endl;
for(auto &pr : m){
cout<<pr.first<<" "<<pr.second<<endl;
}
}

int main(){
map<int,string> m;
//TIME COMPLEXITY OF INSERTION OF ELEMENTS: O(log(n))--> n: size of MAP
m[1] = "abc";
m[5] = "cdc";
m[3] = "acd";
m.insert({4,"abc"});
m.insert({8,"abc"});


// map<int,string> :: iterator it;
// for(it=m.begin();it!=m.end();it++){
// cout<<it->first<<" "<<it->second<<endl;
// }

print(m);

//Find function: takes in key value
// : returns an iterator pointing towards the value
//TIME COMPLEXITY: O(log(n))
// auto it = m.find(9);
// if(it == m.end()){
// cout<<"No such value exists"<<endl;
// }
// else{
// cout<<it->first<<" "<<it->second<<endl;
// }

//ERASE FUNCTION: takes key/iterator as input
// : deletes the specified value if present
//TIME COMPLEXITY: O(log(n))
// auto it = m.find(3);
// m.erase(3);
// print(m);

return 0;
}
Binary file added STL 2.0/MAPS/basics.exe
Binary file not shown.
7 changes: 7 additions & 0 deletions STL 2.0/MAPS/nesting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include<bits/stdc++.h>
using namespace std;

int main(){
map<pair<string,string>,vector<int>> m;
return 0;
}
49 changes: 49 additions & 0 deletions STL 2.0/MAPS/questions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// // /*
// // Given N strings. Print unique strings in lexographical order
// // with their frequency
// // N<= 10^5
// // |S| <= 100
// // */

#include<bits/stdc++.h>
using namespace std;

int main(){
int N;cin>>N;
map<string,int> m;
for(int i=0;i<N;i++){
string s;
cin>>s;
// m[i] = s; //making a map
m[s]++;
}
//Range Based Loop
for(auto pair : m){
cout<<pair.first<<" "<<pair.second<<endl;
}
return 0;
}

// // -------- MONK and class MARKS: Hackerearth -----------
//Please search this question on net for more info
// #include<bits/stdc++.h>
// using namespace std;

// int main(){
// multimap<int,string> list;
// int turn;cin>>turn;
// while(turn--){
// string name; int marks;
// cin>>name>>marks;
// list.insert({marks,name});
// }
// map<int,string> :: iterator it;
// it = (--list.end());
// while(it!=list.begin()){
// cout<<it->second<<" "<<it->first<<endl;
// --it;
// }
// cout<<it->second<<" "<<it->first<<endl;
// return 0;
// }

Binary file added STL 2.0/MAPS/questions.exe
Binary file not shown.
21 changes: 21 additions & 0 deletions STL 2.0/MAPS/unordered.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<bits/stdc++.h>
using namespace std;

int main(){
unordered_map<string,int> m;
int N;cin>>N;
while(N--){
string s;
cin>>s;
m[s]++;
}
int q;cin>>q;
while(q--){
string s;
cin>>s;
cout<<m[s]<<endl;
}


return 0;
}
Binary file added STL 2.0/MAPS/unordered.exe
Binary file not shown.
28 changes: 28 additions & 0 deletions STL 2.0/SETS/intro.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
--------------- ORDERED SET ----------------
Time Complexity: O(log(n))
*/
#include<bits/stdc++.h>
using namespace std;

int main(){
set<string> s;
s.insert("abc");
s.insert("ghi");
s.insert("def");
s.insert("jkl");
s.insert("mnp");
s.insert("abcd");
s.insert("sdwefd");
auto it = s.find("abc");
if(it != s.end()){
// cout<<*it<<endl;
s.erase(it);
}

for(auto val : s){
cout<<val<<endl;
}

return 0;
}
Binary file added STL 2.0/SETS/intro.exe
Binary file not shown.
86 changes: 86 additions & 0 deletions STL 2.0/SETS/questions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//Monk and magical bag question: HACKEREARTH
// #include<bits/stdc++.h>
// using namespace std;

// int main(){
// int turn;
// cin>>turn;
// while(turn--){
// long long N , K; //N--> number of bag, K--> total time he has
// multiset<long long> candies;
// for (long long i = 0; i < N; i++)
// {
// long long A;
// cin>>A;
// candies.insert(A);
// }
// long long eaten = 0;
// while(K--){
// auto last_it = (--candies.end());
// long long candy_ct = *(last_it);
// eaten += candy_ct;
// candies.erase(last_it);
// candies.insert(candy_ct / 2);
// }
// cout<< eaten << endl;
// }

// return 0;
// }

// ------------- SETS : Hackerrank ---------------
// #include<bits/stdc++.h>
// using namespace std;

// int main(){
// int query; cin>>query;
// set<long long> s;
// while(query--){
// long long y,x;
// cin>>y>>x;
// if(y==1){
// s.insert(x);
// }
// else if(y==2){
// auto it = s.find(x);
// if(it==s.end()){
// continue;
// }
// else{
// s.erase(x);
// }
// }
// else if(y==3){
// auto it = s.find(x);
// if(it !=s.end()){
// cout<<"Yes"<<endl;
// }
// else{
// cout<<"No"<<endl;
// }
// }
// }
// return 0;
// }

// ------ MONK BIRTHDAY:Hackerearth -----------
#include<bits/stdc++.h>
using namespace std;

int main(){
int N;cin>>N;
while(N--){
set<string> list;
int num;cin>>num;
while(num--){
string name;
cin>>name;
list.insert(name);
}
for(auto val : list){
cout<< val<<endl;
}
cout<<endl;
}
return 0;
}
37 changes: 37 additions & 0 deletions STL 2.0/SETS/unordered_set.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
------------ Time Complexity ----------------
O(1)
*/
#include<bits/stdc++.h>
using namespace std;

int main(){
unordered_set<string> s;
int N;
cin>>N;
for (int i = 0; i < N; i++)
{
string S;
cin>>S;
s.insert(S);
}
int Q;
cin>>Q;
for (int i = 0; i < Q; i++)
{
string q;
cin>>q;
auto it = s.find(q);
if(it!=s.end()){
cout<<"PRESENT"<<endl;
}
else{
cout<<"NOT PRESENT"<<endl;
}

}



return 0;
}
Binary file added STL 2.0/SETS/unordered_set.exe
Binary file not shown.
23 changes: 23 additions & 0 deletions STL 2.0/Sorting/Upper_Lower_Bound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<bits/stdc++.h>
using namespace std;

int main(){
int n;cin>>n;
int a[n];
for(int i = 0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
for(int i = 0;i<n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
int *ptr = lower_bound(a,a+n,6);
int *ptr2 = upper_bound(a,a+n,25);
if(ptr==a+n && ptr2==a+n){
cout<<"Not Found"<<endl;
return 0;
}
cout<<(*ptr)<<" "<<(*ptr2)<<endl;
return 0;
}
Binary file added STL 2.0/Sorting/Upper_Lower_Bound.exe
Binary file not shown.
16 changes: 16 additions & 0 deletions STL 2.0/Sorting/sort_array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<bits/stdc++.h>
using namespace std;

int main(){
int size;cin>>size;
int a[size];
for(int i=0;i<size;i++){
cin>>a[i];
}
sort(a,a+size);
for(int i=0;i<size;i++){
cout<<a[i]<<" ";
}
cout<<endl;
return 0;
}
Binary file added STL 2.0/Sorting/sort_array.exe
Binary file not shown.
16 changes: 16 additions & 0 deletions STL 2.0/Sorting/sort_vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<bits/stdc++.h>
using namespace std;

int main(){
int n;cin>>n;
vector<int> a(n);
for(int i = 0;i<n;i++){
cin>>a[i];
}
sort(a.begin(),a.end());
for(int i = 0;i<n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
return 0;
}
Binary file added STL 2.0/Sorting/sort_vector.exe
Binary file not shown.
16 changes: 16 additions & 0 deletions STL 2.0/Stacks & Queues/queue_intro.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<bits/stdc++.h>
using namespace std;

int main(){
queue<string> q;
q.push("abc"); //Frontmost element
q.push("bcd");
q.push("dfr");
q.push("wer");
q.push("asx");//Last element
while(!q.empty()){
cout<<q.front()<<" ";
q.pop();
}
return 0;
}
Binary file added STL 2.0/Stacks & Queues/queue_intro.exe
Binary file not shown.
15 changes: 15 additions & 0 deletions STL 2.0/Stacks & Queues/stack_intro.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include<bits/stdc++.h>
using namespace std;

int main(){
stack<int> s;
s.push(2); //First Element
s.push(3);
s.push(4);
s.push(5); //Topmost Element
while(!s.empty()){
cout<<s.top()<<endl;
s.pop();
}
return 0;
}
Binary file added STL 2.0/Stacks & Queues/stack_intro.exe
Binary file not shown.
Loading