diff --git a/Day_31_to_40/Day_40/README.md b/Day_31_to_40/Day_40/README.md index 716b0d3..57f6142 100644 --- a/Day_31_to_40/Day_40/README.md +++ b/Day_31_to_40/Day_40/README.md @@ -1,2 +1,57 @@ # Things I learned in: Day_31_to_40/Day_40 **Note:** use the github provided TOC for navigaing. + + + + +# qsn schedul +1. complete linkedlist theory [x] +2. Creating a Linked List[x] +3. Insertion in the Middle[x] +4. Recursive Reverse a Linked List +5. Recursively Reverse a Linked List Code +6. Iterative Reverse +7. Iteratively Reverse a Linked List Code +8. K-Reverse a Linked List +9. operator overloading[x] +additional +1. string generation acode recursion +2. tower of honoi +3. advanced backtracking webinar + + +# Oracal plane: +1. do most of the problems from fraz sheet +2. complete DSA and OOPs + + cover stack + + cover heap + + cover BT and BST + + Cover hash table + + cover oops + + sorting + + binary search problems + + bitmask + + number theory + + 2d array problems + + Dynamic memory allocation + + cover DP + + cover graph +3. practice on codeforces for time management + + do some ad hoc +4. Practice Apti + + cover probability + + cover loss and profit + + cover men and work +5. practice SQL +6. Prepare for ML interviews + - Do statistics + - Revise previously done ML and DL NLP parts + - Cover Unsupervised Algo + - prepare a bit for tf and pytorch + - cover PCA + - cover EDA + - cover come of the ML interview questions (part 2) +7. Do some Excel and Power Bi +8. Practice python numpy,pandas problems + + diff --git a/Day_31_to_40/Day_40/add_operator_overloading.cpp b/Day_31_to_40/Day_40/add_operator_overloading.cpp new file mode 100644 index 0000000..de585ef --- /dev/null +++ b/Day_31_to_40/Day_40/add_operator_overloading.cpp @@ -0,0 +1,118 @@ +// https://youtu.be/8ymiMHQPgZY +// https://github.com/darkprinx/ACM-SOLUTION/blob/master/Spoj%20Solutions/FILRTEST%20-%20File%20Recover%20Testing.cpp +#include + +using namespace std; + +// void _print(ll t) {cerr << t;} +// void _print(int t) {cerr << t;} +// void _print(string t) {cerr << t;} +// void _print(char t) {cerr << t;} +// void _print(lld t) {cerr << t;} +// void _print(double t) {cerr << t;} +// void _print(ull t) {cerr << t;} + +// template void _print(pair p); +// template void _print(vector v); +// template void _print(set v); +// template void _print(map v); +// template void _print(multiset v); +// template void _print(pair p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} +// template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + + +#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) +#define MOD 1000000007 +#define MOD1 998244353 +#define INF 1e18 +#define nline "\n" +#define pb push_back +#define ppb pop_back +#define mp make_pair +#define ff first +#define ss second +#define PI 3.141592653589793238462 +#define set_bits __builtin_popcountll +#define sz(x) ((int)(x).size()) +#define all(x) (x).begin(), (x).end() +#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) +#define print_vec(x) for(auto i:x) cout< vi; +typedef vector vll; +typedef pair pii; +typedef pair pll; +typedef pair pib; +typedef pair pdd; +typedef pair pid; +typedef pair< int, pii> ipii; +// typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Code Below ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// https://youtu.be/BO2KagRMS3M +class Complex{ +private: + int real,imag; +public: + // default constructor + Complex(){ + real = 0; + imag = 0; + } + // user defined constructor + Complex(int r,int i){ + real = r; + imag = i; + } + void print(){ + cout<< real<<"+"< + +using namespace std; + +// void _print(ll t) {cerr << t;} +// void _print(int t) {cerr << t;} +// void _print(string t) {cerr << t;} +// void _print(char t) {cerr << t;} +// void _print(lld t) {cerr << t;} +// void _print(double t) {cerr << t;} +// void _print(ull t) {cerr << t;} + +// template void _print(pair p); +// template void _print(vector v); +// template void _print(set v); +// template void _print(map v); +// template void _print(multiset v); +// template void _print(pair p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} +// template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + + +#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) +#define MOD 1000000007 +#define MOD1 998244353 +#define INF 1e18 +#define nline "\n" +#define pb push_back +#define ppb pop_back +#define mp make_pair +#define ff first +#define ss second +#define PI 3.141592653589793238462 +#define set_bits __builtin_popcountll +#define sz(x) ((int)(x).size()) +#define all(x) (x).begin(), (x).end() +#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) +#define print_vec(x) for(auto i:x) cout< vi; +typedef vector vll; +typedef pair pii; +typedef pair pll; +typedef pair pib; +typedef pair pdd; +typedef pair pid; +typedef pair< int, pii> ipii; +// typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Code Below ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +class node{ +public: + int data; + node*next; + + node(int d){ + data = d; + next = NULL; + } + ~node(){ + if(next!=NULL){ + delete next; + } + } +}; + +void print_ll(node* head){ // at the print time we dont pass by reference + while(head!=NULL){ + cout<data<<", "; + head = head->next; + } + cout<next = head; + head= n; +} + +node* take_input(){ + int d; + cin>>d; // taking the data + node* head = NULL; // creating the head pointer + + while(d!=-1){ // - + untill user provides -1 as the input we ill keep taking input from user + insert_head(head,d); // | and insert in the head(we can use other insert operations too) + cin>>d; // | and take input from the user, which will eventually update d. + } // - + + return head; // we return head as we are not taking head in the function input. +} + + +node* take_input_txt(){ + int d; + node* head = NULL; + + cin>>d; + while(d!=-1){ + insert_head(head,d); + cin>>d; + } + + return head; +} + + +ostream& operator<<(ostream &os,node* head){ + print_ll(head); + return os; +} + +istream& operator>>(istream &is, node*&head){ + head = take_input_txt(); + return is; +} + + +int main() { +#ifndef ONLINE_JUDGE + freopen("errorf.in", "w", stderr); +#endif + + fastio(); + node*head; + node*head2; + + cin>>head; + cin>>head2; + cout< + +using namespace std; + +// void _print(ll t) {cerr << t;} +// void _print(int t) {cerr << t;} +// void _print(string t) {cerr << t;} +// void _print(char t) {cerr << t;} +// void _print(lld t) {cerr << t;} +// void _print(double t) {cerr << t;} +// void _print(ull t) {cerr << t;} + +// template void _print(pair p); +// template void _print(vector v); +// template void _print(set v); +// template void _print(map v); +// template void _print(multiset v); +// template void _print(pair p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} +// template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + + +#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) +#define MOD 1000000007 +#define MOD1 998244353 +#define INF 1e18 +#define nline "\n" +#define pb push_back +#define ppb pop_back +#define mp make_pair +#define ff first +#define ss second +#define PI 3.141592653589793238462 +#define set_bits __builtin_popcountll +#define sz(x) ((int)(x).size()) +#define all(x) (x).begin(), (x).end() +#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) +#define print_vec(x) for(auto i:x) cout< vi; +typedef vector vll; +typedef pair pii; +typedef pair pll; +typedef pair pib; +typedef pair pdd; +typedef pair pid; +typedef pair< int, pii> ipii; +// typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Code Below ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +class node{ +public: + int data; + node*next; + + node(int d){ + data = d; + next = NULL; + } + ~node(){ + if(next!=NULL){ + delete next; + } + } +}; + +void print_ll(node* head){ // at the print time we dont pass by reference + while(head!=NULL){ + cout<data<<", "; + head = head->next; + } + cout<next = head; + head= n; +} + +node* take_input(){ + int d; + cin>>d; // taking the data + node* head = NULL; // creating the head pointer + + while(d!=-1){ // - + untill user provides -1 as the input we ill keep taking input from user + insert_head(head,d); // | and insert in the head(we can use other insert operations too) + cin>>d; // | and take input from the user, which will eventually update d. + } // - + + return head; // we return head as we are not taking head in the function input. +} + + +node* take_input_txt(){ + int d; + node* head = NULL; + + cin>>d; + while(d!=-1){ + insert_head(head,d); + cin>>d; + } + + return head; +} + + +ostream& operator<<(ostream &os,node* head){ + print_ll(head); + return os; +} + +istream& operator>>(istream &is, node*&head){ + head = take_input_txt(); + return is; +} + + +// reverse Linked List using recursion +void reverse_ll(node* &head){ + // think this is a ll: 1->2->3->NULL + node* prev = NULL; + node* c = head; + node* n; + while(c !=NULL){ + n = c->next; // now n is pointing to 2 + c->next = prev; + prev = c; + c =n; + } + head = prev; + return; +} + +node* reverse_rec(node* &head){ + if(head=NULL or head->next == NULL){ + return head; + } + + // do recurcive case + node* shead = reverse_rec(head->next); + node* temp = shead; + while(temp->next!=NULL){ + temp = temp->next; + } + head->next = NULL; + temp->next = head; + + return shead; +} + +// https://ide.codingblocks.com/s/610493 +node* kth_element(node*&head,int k) +{ + node * slow = head; + node * fast = head; + while(k--) + { + fast = fast->next; + } + while(fast!=NULL) + { + fast = fast->next; + slow = slow->next; + } + return slow; +} + +int main() { +#ifndef ONLINE_JUDGE + freopen("errorf.in", "w", stderr); +#endif + + fastio(); + node*head; + cin>>head; + cout<>head2; + // cout< + +using namespace std; + +// void _print(ll t) {cerr << t;} +// void _print(int t) {cerr << t;} +// void _print(string t) {cerr << t;} +// void _print(char t) {cerr << t;} +// void _print(lld t) {cerr << t;} +// void _print(double t) {cerr << t;} +// void _print(ull t) {cerr << t;} + +// template void _print(pair p); +// template void _print(vector v); +// template void _print(set v); +// template void _print(map v); +// template void _print(multiset v); +// template void _print(pair p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} +// template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + + +#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) +#define MOD 1000000007 +#define MOD1 998244353 +#define INF 1e18 +#define nline "\n" +#define pb push_back +#define ppb pop_back +#define mp make_pair +#define ff first +#define ss second +#define PI 3.141592653589793238462 +#define set_bits __builtin_popcountll +#define sz(x) ((int)(x).size()) +#define all(x) (x).begin(), (x).end() +#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) +#define print_vec(x) for(auto i:x) cout< vi; +typedef vector vll; +typedef pair pii; +typedef pair pll; +typedef pair pib; +typedef pair pdd; +typedef pair pid; +typedef pair< int, pii> ipii; +// typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Code Below ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +class node{ +public: + int data; + node*next; + + node(int d){ + data = d; + next = NULL; + } + ~node(){ + if(next!=NULL){ + delete next; + } + } +}; + +void print_ll(node* head){ // at the print time we dont pass by reference + while(head!=NULL){ + cout<data<<", "; + head = head->next; + } + cout<next = head; + head= n; +} + +node* take_input(){ + int d; + cin>>d; // taking the data + node* head = NULL; // creating the head pointer + + while(d!=-1){ // - + untill user provides -1 as the input we ill keep taking input from user + insert_head(head,d); // | and insert in the head(we can use other insert operations too) + cin>>d; // | and take input from the user, which will eventually update d. + } // - + + return head; // we return head as we are not taking head in the function input. +} + + +node* take_input_txt(){ + int d; + node* head = NULL; + + cin>>d; + while(d!=-1){ + insert_head(head,d); + cin>>d; + } + + return head; +} + + +ostream& operator<<(ostream &os,node* head){ + print_ll(head); + return os; +} + +istream& operator>>(istream &is, node*&head){ + head = take_input_txt(); + return is; +} + + +// reverse Linked List using recursion +void reverse_ll(node* &head){ + // think this is a ll: 1->2->3->NULL + node* prev = NULL; + node* c = head; + node* n; + while(c !=NULL){ + n = c->next; // now n is pointing to 2 + c->next = prev; + prev = c; + c =n; + } + head = prev; + return; +} + +int main() { +#ifndef ONLINE_JUDGE + freopen("errorf.in", "w", stderr); +#endif + + fastio(); + node*head; + cin>>head; + cout<>head2; + // cout< + +using namespace std; + +// void _print(ll t) {cerr << t;} +// void _print(int t) {cerr << t;} +// void _print(string t) {cerr << t;} +// void _print(char t) {cerr << t;} +// void _print(lld t) {cerr << t;} +// void _print(double t) {cerr << t;} +// void _print(ull t) {cerr << t;} + +// template void _print(pair p); +// template void _print(vector v); +// template void _print(set v); +// template void _print(map v); +// template void _print(multiset v); +// template void _print(pair p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} +// template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +// template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + + +#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) +#define MOD 1000000007 +#define MOD1 998244353 +#define INF 1e18 +#define nline "\n" +#define pb push_back +#define ppb pop_back +#define mp make_pair +#define ff first +#define ss second +#define PI 3.141592653589793238462 +#define set_bits __builtin_popcountll +#define sz(x) ((int)(x).size()) +#define all(x) (x).begin(), (x).end() +#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) +#define print_vec(x) for(auto i:x) cout< vi; +typedef vector vll; +typedef pair pii; +typedef pair pll; +typedef pair pib; +typedef pair pdd; +typedef pair pid; +typedef pair< int, pii> ipii; +// typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Code Below ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +class node{ +public: + int data; + node*next; + + node(int d){ + data = d; + next = NULL; + } + ~node(){ + if(next!=NULL){ + delete next; + } + } +}; + +void print_ll(node* head){ // at the print time we dont pass by reference + while(head!=NULL){ + cout<data<<", "; + head = head->next; + } + cout<next = head; + head= n; +} + +node* take_input(){ + int d; + cin>>d; // taking the data + node* head = NULL; // creating the head pointer + + while(d!=-1){ // - + untill user provides -1 as the input we ill keep taking input from user + insert_head(head,d); // | and insert in the head(we can use other insert operations too) + cin>>d; // | and take input from the user, which will eventually update d. + } // - + + return head; // we return head as we are not taking head in the function input. +} + + +node* take_input_txt(){ + int d; + node* head = NULL; + + cin>>d; + while(d!=-1){ + insert_head(head,d); + cin>>d; + } + + return head; +} + + +ostream& operator<<(ostream &os,node* head){ + print_ll(head); + return os; +} + +istream& operator>>(istream &is, node*&head){ + head = take_input_txt(); + return is; +} + + +// reverse Linked List using recursion +void reverse_ll(node* &head){ + // think this is a ll: 1->2->3->NULL + node* prev = NULL; + node* c = head; + node* n; + while(c !=NULL){ + n = c->next; // now n is pointing to 2 + c->next = prev; + prev = c; + c =n; + } + head = prev; + return; +} + +node* reverse_rec(node* &head){ + if(head=NULL or head->next == NULL){ + return head; + } + + // do recurcive case + node* shead = reverse_rec(head->next); + node* temp = shead; + while(temp->next!=NULL){ + temp = temp->next; + } + head->next = NULL; + temp->next = head; + + return shead; +} + + + +int main() { +#ifndef ONLINE_JUDGE + freopen("errorf.in", "w", stderr); +#endif + + fastio(); + node*head; + cin>>head; + cout<>head2; + // cout<