From 53d890b85f064e25f22f4591ea19af388118d5f8 Mon Sep 17 00:00:00 2001 From: Martin Ayush Date: Mon, 11 Oct 2021 11:12:55 +0530 Subject: [PATCH 1/2] resolved Unable to checkout error --- C/Date-to-day.c | 154 ++-- C/SumOfArray.c | 86 +-- C/main.c | 104 +-- CPP STL/algorithm/algorithm.cpp | 164 ++-- CPP STL/basic_stl.cpp | 60 +- CPP STL/iterators/iterators.cpp | 94 +-- CPP STL/iterators/iterators_part2.cpp | 54 +- CPP STL/pairs/pairs.cpp | 94 +-- CPP STL/pairs/sorting_pair_arrays.cpp | 76 +- CPP STL/templates/class_template.cpp | 76 +- CPP STL/templates/functional_temp_part2.cpp | 68 +- CPP STL/templates/functional_template.cpp | 58 +- CPP STL/templates/template_example.cpp | 38 +- CPP STL/vector/funcn_part2.cpp | 130 ++-- CPP STL/vector/funcn_part3.cpp | 22 +- CPP STL/vector/subsetSum_mod_k.cpp | 92 +-- CPP STL/vector/vactor_othr_fucn.cpp | 140 ++-- CPP STL/vector/vector1.cpp | 58 +- CPP STL/vector/vector2.cpp | 60 +- CPP STL/vector/vector3.cpp | 36 +- CPP STL/vector/vector4.cpp | 38 +- CPP/1 Two Sum.cpp | 78 +- CPP/BST implementation.cpp | 514 ++++++------- CPP/Bellman-Ford-Algo.cpp | 244 +++--- ...Create Queue Uisng Two Stacks Approach.cpp | 146 ++-- CPP/DecimalToBinary.cpp | 60 +- CPP/Doubly linked list.cpp | 710 +++++++++--------- CPP/FindingPairSumHashTable.cpp | 66 +- CPP/GfgDsa/Introduction/digitCount | Bin CPP/GfgDsa/Introduction/hcf | Bin CPP/GfgDsa/Introduction/recursion | Bin CPP/GfgDsa/Introduction/trail | Bin CPP/LRU Cache Implementation.cpp | 426 +++++------ CPP/Merge two sorted arrays.cpp | 104 +-- CPP/MissingDifferentOrder.cpp | 42 +- CPP/Mo'salgo.cpp | 210 +++--- CPP/Recursive Binary Search.cpp | 86 +-- ...rse a Linked List in groups of given size. | 134 ---- CPP/SPOJ_Mixtures.cpp | 134 ++-- CPP/Shell_Sort.cpp | 168 ++--- CPP/Singly Linked List.cpp | 528 ++++++------- CPP/Stock-Span-Problem.cpp | 66 +- CPP/Strassens matrix multiplication.cpp | 126 ++-- CPP/TappinrainWater.cpp | 50 +- CPP/Trapping-Rain-Water.cpp | 76 +- CPP/TravellingSalesmanProblem.cpp | 144 ++-- CPP/armstrong.cpp | 60 +- CPP/chocolatedistribution.cpp | 36 +- CPP/funcmaxmin.cpp | 110 +-- CPP/insertionsort_code.cpp | 68 +- CPP/kruskals.cpp | 150 ++-- CPP/prims.cpp | 158 ++-- CPP/stack.cpp | 142 ++-- CPP/tsort.cpp | 208 ++--- DSA-c++ | 1 - JAVA/Matrix.java | 160 ++-- JAVA/armstrong.java | 44 +- JAVA/complex.java | 100 +-- JAVA/remove_duplicates_from_names.java | 36 +- JavaScript/Breakout_Game/app.js | 422 +++++------ JavaScript/Breakout_Game/index.html | 54 +- JavaScript/Breakout_Game/plan.txt | 22 +- JavaScript/Breakout_Game/style.css | 140 ++-- JavaScript/Sorting/MergeSort.js | 53 -- JavaScript/dice_game_project_3 | 1 - JavaScript/expense tracker/app .js | 486 ++++++------ JavaScript/expense tracker/index .html | 116 +-- JavaScript/expense tracker/style .css | 356 ++++----- JavaScript/noob-load | 1 - PHP/CRUD | 1 - PYTHON/Bubble Sort.py | 38 +- PYTHON/Guessing Game.py | 44 +- PYTHON/lorentz_attractor.py | 86 +-- PYTHON/palindrome and symmetry.py | 126 ++-- PYTHON/search.py | 36 +- PYTHON/temperature_converter.py | 26 +- 76 files changed, 4452 insertions(+), 4643 deletions(-) mode change 100755 => 100644 CPP/GfgDsa/Introduction/digitCount mode change 100755 => 100644 CPP/GfgDsa/Introduction/hcf mode change 100755 => 100644 CPP/GfgDsa/Introduction/recursion mode change 100755 => 100644 CPP/GfgDsa/Introduction/trail delete mode 100644 CPP/Reverse a Linked List in groups of given size. delete mode 160000 DSA-c++ delete mode 100644 JavaScript/Sorting/MergeSort.js delete mode 160000 JavaScript/dice_game_project_3 delete mode 160000 JavaScript/noob-load delete mode 160000 PHP/CRUD diff --git a/C/Date-to-day.c b/C/Date-to-day.c index ba03a07f..f06ed552 100644 --- a/C/Date-to-day.c +++ b/C/Date-to-day.c @@ -1,78 +1,78 @@ -#include - -/* - * function: validateDate - * arguments: d- day, m- month, y- year - * return type: 0 - invalid, 1 - valid - * */ -int validateDate(int d, int m, int y) -{ - //check year validity - if (y >= 1800 && y <= 2999) { - //check month validity - if (m >= 1 && m <= 12) { - //check day validity - if (d >= 1 && d <= 31) { - if ((d >= 1 && d <= 30) && (m == 4 || m == 6 || m == 9 || m == 11)) - return 1; //valid date - else if ((d >= 1 && d <= 30) && (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)) - return 1; //valid date - else if ((d >= 1 && d <= 28) && (m == 2)) - return 1; //valid date - else if (d == 29 && m == 2 && ((y % 400 == 0) || (y % 4 == 0 && y % 4 != 0))) - return 1; //valid date - else - return 0; //invalid day - } - else { - printf("\nTHERE IS NO SUCH MONTH DATE SO ADD CAREFULLY"); - return 0; //day is invalid - } - } - else { - printf("\nTHERE ARE ONLY 12 MONTHS AS PER NOW SO JUST ADD DATE WITHIN IT"); - return 0; //month is invalid - } - } - else { - printf("\nPLZ ENTER YEAR FROM 1800 TO 2999"); - return 0; //year is invalid - } -} -// This function will return week day number from 0 to 6 -int wd(int year, int month, int day) -{ - int wday = 0; - wday = (day + ((153 * (month + 12 * ((14 - month) / 12) - 3) + 2) / 5) - + (365 * (year + 4800 - ((14 - month) / 12))) - + ((year + 4800 - ((14 - month) / 12)) / 4) - - ((year + 4800 - ((14 - month) / 12)) / 100) - + ((year + 4800 - ((14 - month) / 12)) / 400) - - 32045) - % 7; - return wday; -} - -int main() -{ - int day, month, year; - int wDayNo = 0; - char dayNames[][12] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; - - //input date - printf("Input date (DD-MM-YYYY): "); - scanf("%d-%d-%d", &day, &month, &year); - - //check date is correct or not - if (validateDate(day, month, year) == 1) { - printf("Date is correct [%02d/%02d/%02d].\n", day, month, year); - //get weekday number - wDayNo = wd(year, month, day); - //print weekday according to wDayNo - printf("week day is: %s\n", dayNames[wDayNo]); - } - else - printf("\nDate is in-correct.\n"); - - return 0; +#include + +/* + * function: validateDate + * arguments: d- day, m- month, y- year + * return type: 0 - invalid, 1 - valid + * */ +int validateDate(int d, int m, int y) +{ + //check year validity + if (y >= 1800 && y <= 2999) { + //check month validity + if (m >= 1 && m <= 12) { + //check day validity + if (d >= 1 && d <= 31) { + if ((d >= 1 && d <= 30) && (m == 4 || m == 6 || m == 9 || m == 11)) + return 1; //valid date + else if ((d >= 1 && d <= 30) && (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)) + return 1; //valid date + else if ((d >= 1 && d <= 28) && (m == 2)) + return 1; //valid date + else if (d == 29 && m == 2 && ((y % 400 == 0) || (y % 4 == 0 && y % 4 != 0))) + return 1; //valid date + else + return 0; //invalid day + } + else { + printf("\nTHERE IS NO SUCH MONTH DATE SO ADD CAREFULLY"); + return 0; //day is invalid + } + } + else { + printf("\nTHERE ARE ONLY 12 MONTHS AS PER NOW SO JUST ADD DATE WITHIN IT"); + return 0; //month is invalid + } + } + else { + printf("\nPLZ ENTER YEAR FROM 1800 TO 2999"); + return 0; //year is invalid + } +} +// This function will return week day number from 0 to 6 +int wd(int year, int month, int day) +{ + int wday = 0; + wday = (day + ((153 * (month + 12 * ((14 - month) / 12) - 3) + 2) / 5) + + (365 * (year + 4800 - ((14 - month) / 12))) + + ((year + 4800 - ((14 - month) / 12)) / 4) + - ((year + 4800 - ((14 - month) / 12)) / 100) + + ((year + 4800 - ((14 - month) / 12)) / 400) + - 32045) + % 7; + return wday; +} + +int main() +{ + int day, month, year; + int wDayNo = 0; + char dayNames[][12] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; + + //input date + printf("Input date (DD-MM-YYYY): "); + scanf("%d-%d-%d", &day, &month, &year); + + //check date is correct or not + if (validateDate(day, month, year) == 1) { + printf("Date is correct [%02d/%02d/%02d].\n", day, month, year); + //get weekday number + wDayNo = wd(year, month, day); + //print weekday according to wDayNo + printf("week day is: %s\n", dayNames[wDayNo]); + } + else + printf("\nDate is in-correct.\n"); + + return 0; } \ No newline at end of file diff --git a/C/SumOfArray.c b/C/SumOfArray.c index 91117481..b1659668 100644 --- a/C/SumOfArray.c +++ b/C/SumOfArray.c @@ -1,44 +1,44 @@ -#include -#include -#include - -void main() -{ - - int i, n; - int *a, *b, *c; - - printf("Enter the size of the arrays\n"); - scanf("%d", &n); - - a = (int *)malloc(n * sizeof(int)); - b = (int *)malloc(n * sizeof(int)); - c = (int *)malloc(n * sizeof(int)); - - printf("Enter Elements of First List\n"); - - for (i = 0; i < n; i++) - { - scanf("%d", a + i); - } - - printf("Enter Elements of Second List\n"); - - for (i = 0; i < n; i++) - { - scanf("%d", b + i); - } - - for (i = 0; i < n; i++) - { - *(c + i) = *(a + i) + *(b + i); - } - - printf("Resultant List is\n"); - - for (i = 0; i < n; i++) - { - printf("%d\n", *(c + i)); - } - return 0; +#include +#include +#include + +void main() +{ + + int i, n; + int *a, *b, *c; + + printf("Enter the size of the arrays\n"); + scanf("%d", &n); + + a = (int *)malloc(n * sizeof(int)); + b = (int *)malloc(n * sizeof(int)); + c = (int *)malloc(n * sizeof(int)); + + printf("Enter Elements of First List\n"); + + for (i = 0; i < n; i++) + { + scanf("%d", a + i); + } + + printf("Enter Elements of Second List\n"); + + for (i = 0; i < n; i++) + { + scanf("%d", b + i); + } + + for (i = 0; i < n; i++) + { + *(c + i) = *(a + i) + *(b + i); + } + + printf("Resultant List is\n"); + + for (i = 0; i < n; i++) + { + printf("%d\n", *(c + i)); + } + return 0; } \ No newline at end of file diff --git a/C/main.c b/C/main.c index c1b2ef7f..5b52a62c 100644 --- a/C/main.c +++ b/C/main.c @@ -1,52 +1,52 @@ -#include -#include - -int main() -{ - int a,b,i,c,sum=0,Mul=1; - printf("Enter first Number:"); - scanf("%d",&a); - printf("\nEnter last Number:"); - scanf("%d",&b); - printf("All odd numbers from %d-%d are:\n",a,b); - for (i=a;i<=b;i++) - { - if (i%2==1) - { - printf("%d\n",i); - } - } - printf("\n\tTo get Addition of that numbers Press 1:"); - printf("\n\tTo get Multiplication of that numbers press 2:"); - printf("\n\tpress:"); - scanf("%d",&c); - switch (c) - { - { -case 1: - { - for (i=a;i<=b;i++) - { - if(i%2==1) - { - sum=sum+i; - } - } - printf("Addition is:%d",sum); - break; - } - case 2: - { - for(i=a;i<=b;i++) - { - if(i%2==1) - { - Mul=Mul*i; - } - } - printf("Multiplication is:%d",Mul); - } - } - return 0; -} -} +#include +#include + +int main() +{ + int a,b,i,c,sum=0,Mul=1; + printf("Enter first Number:"); + scanf("%d",&a); + printf("\nEnter last Number:"); + scanf("%d",&b); + printf("All odd numbers from %d-%d are:\n",a,b); + for (i=a;i<=b;i++) + { + if (i%2==1) + { + printf("%d\n",i); + } + } + printf("\n\tTo get Addition of that numbers Press 1:"); + printf("\n\tTo get Multiplication of that numbers press 2:"); + printf("\n\tpress:"); + scanf("%d",&c); + switch (c) + { + { +case 1: + { + for (i=a;i<=b;i++) + { + if(i%2==1) + { + sum=sum+i; + } + } + printf("Addition is:%d",sum); + break; + } + case 2: + { + for(i=a;i<=b;i++) + { + if(i%2==1) + { + Mul=Mul*i; + } + } + printf("Multiplication is:%d",Mul); + } + } + return 0; +} +} diff --git a/CPP STL/algorithm/algorithm.cpp b/CPP STL/algorithm/algorithm.cpp index 24230c9d..6d4030c5 100644 --- a/CPP STL/algorithm/algorithm.cpp +++ b/CPP STL/algorithm/algorithm.cpp @@ -1,82 +1,82 @@ -// These algoritms may be applied to most of the stl containers -// we will implement them in vector here -#include -#include -#include - -using namespace std; - -int main() -{ - vector v; - v.push_back(2); - // v.push_back(5); - v.push_back(4); - v.push_back(1); - v.push_back(6); - v.push_back(3); - v.push_back(7); - - // binary search - to search if an element is present - cout << "Check if 6 is present in vector- "; - cout << binary_search(v.begin(), v.end(), 6) << endl; - - // lower bound:- The element just greater than given element - cout << "The lower bound for 5 is "; - cout << lower_bound(v.begin(), v.end(), 5) - v.begin() << endl; - - // upper bound:- The element just smaller than the given element - cout << "The upper bound for 5 is "; - cout << upper_bound(v.begin(), v.end(), 6) - v.begin() << endl; - - // maximum of two number - int a = 8, b = 10; - cout << "Maximum of " << a << " and " << b << " is " << max(a, b) << endl; - - // minimum of two no. - cout << "Minimum of " << a << " and " << b << " is " << min(a, b) << endl; - - // swap function to replace the value among themselves - cout << "Earlier a=" << a << " and b=" << b << endl; - swap(a, b); - cout << "Now a=" << a << " and b=" << b << endl; - - // reverse the container - cout << "Before reversing vector : "; - for (auto i : v) - cout << i << " "; - cout << endl; - // calling the reverse function - reverse(v.begin(), v.end()); - cout << "After reversing vector : "; - for (auto i : v) - cout << i << " "; - cout << endl; - - // rotate - it will rotate by provided position - cout << "Before rotating vector : "; - for (auto i : v) - cout << i << " "; - cout << endl; - // calling the rotate function - rotate(v.begin(), v.begin() + 1, v.end()); - cout << "After rotating vector by 1 : "; - for (auto i : v) - cout << i << " "; - cout << endl; - - // sorting the container - // it is based on intro sort(quick sort + heap sort + insertion sort) - cout << "Before sorting vector : "; - for (auto i : v) - cout << i << " "; - cout << endl; - // calling the rotate function - sort(v.begin(), v.end()); - cout << "After sorting vector : "; - for (auto i : v) - cout << i << " "; - cout << endl; - - return 0; -} +// These algoritms may be applied to most of the stl containers +// we will implement them in vector here +#include +#include +#include + +using namespace std; + +int main() +{ + vector v; + v.push_back(2); + // v.push_back(5); + v.push_back(4); + v.push_back(1); + v.push_back(6); + v.push_back(3); + v.push_back(7); + + // binary search - to search if an element is present + cout << "Check if 6 is present in vector- "; + cout << binary_search(v.begin(), v.end(), 6) << endl; + + // lower bound:- The element just greater than given element + cout << "The lower bound for 5 is "; + cout << lower_bound(v.begin(), v.end(), 5) - v.begin() << endl; + + // upper bound:- The element just smaller than the given element + cout << "The upper bound for 5 is "; + cout << upper_bound(v.begin(), v.end(), 6) - v.begin() << endl; + + // maximum of two number + int a = 8, b = 10; + cout << "Maximum of " << a << " and " << b << " is " << max(a, b) << endl; + + // minimum of two no. + cout << "Minimum of " << a << " and " << b << " is " << min(a, b) << endl; + + // swap function to replace the value among themselves + cout << "Earlier a=" << a << " and b=" << b << endl; + swap(a, b); + cout << "Now a=" << a << " and b=" << b << endl; + + // reverse the container + cout << "Before reversing vector : "; + for (auto i : v) + cout << i << " "; + cout << endl; + // calling the reverse function + reverse(v.begin(), v.end()); + cout << "After reversing vector : "; + for (auto i : v) + cout << i << " "; + cout << endl; + + // rotate - it will rotate by provided position + cout << "Before rotating vector : "; + for (auto i : v) + cout << i << " "; + cout << endl; + // calling the rotate function + rotate(v.begin(), v.begin() + 1, v.end()); + cout << "After rotating vector by 1 : "; + for (auto i : v) + cout << i << " "; + cout << endl; + + // sorting the container + // it is based on intro sort(quick sort + heap sort + insertion sort) + cout << "Before sorting vector : "; + for (auto i : v) + cout << i << " "; + cout << endl; + // calling the rotate function + sort(v.begin(), v.end()); + cout << "After sorting vector : "; + for (auto i : v) + cout << i << " "; + cout << endl; + + return 0; +} diff --git a/CPP STL/basic_stl.cpp b/CPP STL/basic_stl.cpp index 206c3bd9..4fe57061 100644 --- a/CPP STL/basic_stl.cpp +++ b/CPP STL/basic_stl.cpp @@ -1,30 +1,30 @@ -#include -//#include - -using namespace std; - -//#define int long long - -int main() -{ - int arr[] = {10, 222, 30, 4, 99, 55, 144, 551}; - int size = sizeof arr / sizeof arr[0]; - cout << "size is " << size << endl; - sort(arr, arr + size); - for (int i = 0; i < size; i++) - { - /* code */ - cout << arr[i] << " " - << "\n"; - } - int it= lower_bound(arr, arr + size, 55)-arr; - - if (arr[it]==55) - { - cout << "present at "< +//#include + +using namespace std; + +//#define int long long + +int main() +{ + int arr[] = {10, 222, 30, 4, 99, 55, 144, 551}; + int size = sizeof arr / sizeof arr[0]; + cout << "size is " << size << endl; + sort(arr, arr + size); + for (int i = 0; i < size; i++) + { + /* code */ + cout << arr[i] << " " + << "\n"; + } + int it= lower_bound(arr, arr + size, 55)-arr; + + if (arr[it]==55) + { + cout << "present at "< - -#include - -using namespace std; - -/* -begin():- it will give the first position of array element -end():- it goes beyond the last element.. it point the element after the last element -*/ - -int main() -{ - - vector v = {10, 20, 60, 8, 9, 6, 5, 147, 89}; - //vector::iterator i = v.begin(); - auto i=v.begin(); - - for (i; i < v.end(); i++) - { - cout << *i << " "; - } - cout << "\n" - << "reverse is : " - << "\n"; - for (i = v.end() - 1; i >= v.begin(); i--) - { - cout << *i << " "; - } - - /* - // vector::iterator i = v.begin(); can be replaced with auto i=v.begin(); - - for (auto i = v.begin(); i < v.end(); i++) - { - cout << *i << " "; - } - - - cout << "reverse order : " - << "\n"; - for (auto i = v.end() - 1; i >= v.begin(); i--) - { - cout << *i << " "; - } -*/ - return 0; +#include + +#include + +using namespace std; + +/* +begin():- it will give the first position of array element +end():- it goes beyond the last element.. it point the element after the last element +*/ + +int main() +{ + + vector v = {10, 20, 60, 8, 9, 6, 5, 147, 89}; + //vector::iterator i = v.begin(); + auto i=v.begin(); + + for (i; i < v.end(); i++) + { + cout << *i << " "; + } + cout << "\n" + << "reverse is : " + << "\n"; + for (i = v.end() - 1; i >= v.begin(); i--) + { + cout << *i << " "; + } + + /* + // vector::iterator i = v.begin(); can be replaced with auto i=v.begin(); + + for (auto i = v.begin(); i < v.end(); i++) + { + cout << *i << " "; + } + + + cout << "reverse order : " + << "\n"; + for (auto i = v.end() - 1; i >= v.begin(); i--) + { + cout << *i << " "; + } +*/ + return 0; } \ No newline at end of file diff --git a/CPP STL/iterators/iterators_part2.cpp b/CPP STL/iterators/iterators_part2.cpp index c7d687ef..abb20af9 100644 --- a/CPP STL/iterators/iterators_part2.cpp +++ b/CPP STL/iterators/iterators_part2.cpp @@ -1,28 +1,28 @@ -#include - -using namespace std; -/* -i=next(i)= by default it will move one position ahead -i=next(i,4)= in this case it will move 4 position ahead -i=prev(i)= by default it will ove one position back -i=prev(i,3)= if u pass a parameter, then it will move that many position back -advance(i,4)= it is Slightly differnet from next.. next returns the iterartor, -advance modify the same past iterators -*/ - -int main() -{ - vector v = {10, 20, 30, 40, 50, 60}; - vector::iterator i = v.begin(); - cout << *i << "\n"; - i = next(i,2); - cout << *i << "\n"; - advance(i, 2); - cout << *i << "\n"; - i=prev(i); - cout << *i << "\n"; - i=prev(i,3); - cout << *i << "\n"; - - return 0; +#include + +using namespace std; +/* +i=next(i)= by default it will move one position ahead +i=next(i,4)= in this case it will move 4 position ahead +i=prev(i)= by default it will ove one position back +i=prev(i,3)= if u pass a parameter, then it will move that many position back +advance(i,4)= it is Slightly differnet from next.. next returns the iterartor, +advance modify the same past iterators +*/ + +int main() +{ + vector v = {10, 20, 30, 40, 50, 60}; + vector::iterator i = v.begin(); + cout << *i << "\n"; + i = next(i,2); + cout << *i << "\n"; + advance(i, 2); + cout << *i << "\n"; + i=prev(i); + cout << *i << "\n"; + i=prev(i,3); + cout << *i << "\n"; + + return 0; } \ No newline at end of file diff --git a/CPP STL/pairs/pairs.cpp b/CPP STL/pairs/pairs.cpp index 57b294b0..61636506 100644 --- a/CPP STL/pairs/pairs.cpp +++ b/CPP STL/pairs/pairs.cpp @@ -1,48 +1,48 @@ -#include -// #include - -// #include - -using namespace std; - -//#define int long long - -pair p1(10, 20), p2(10, 20), p4; - -int main() -{ - //type:-1 - pair PAIR1; - PAIR1.first = 100; - PAIR1.second = 'G'; - cout << PAIR1.first << " "; - cout << PAIR1.second << endl; - //type:-2 - pair PAIR2("shubham", 1.23); - cout << PAIR2.first << " "; - cout << PAIR2.second << endl; - //type:-3 - pair PAIR3; - PAIR3 = make_pair("my dad is Best", 4.56); - cout << PAIR3.first << " "; - cout << PAIR3.second << endl; - //type:-4 - pair PAIR4; - PAIR4 = {100, 220}; - cout << PAIR4.first << " "; - cout << PAIR4.second << endl; - cout << "//output of comparison operator//" << endl; - - cout - << p1.first << " " << p1.second << endl; - cout << p2.first << " " << p2.second << endl; - cout << p4.first << " " << p4.second << endl; - cout << (p1 == p2) << endl; - cout << (p1 != p2) << endl; - cout << (p1 < p2) << endl; - cout << (p1 > p2) << endl; - cout << (p1 <= p2) << endl; - cout << (p1 >= p2) << endl; - - return 0; +#include +// #include + +// #include + +using namespace std; + +//#define int long long + +pair p1(10, 20), p2(10, 20), p4; + +int main() +{ + //type:-1 + pair PAIR1; + PAIR1.first = 100; + PAIR1.second = 'G'; + cout << PAIR1.first << " "; + cout << PAIR1.second << endl; + //type:-2 + pair PAIR2("shubham", 1.23); + cout << PAIR2.first << " "; + cout << PAIR2.second << endl; + //type:-3 + pair PAIR3; + PAIR3 = make_pair("my dad is Best", 4.56); + cout << PAIR3.first << " "; + cout << PAIR3.second << endl; + //type:-4 + pair PAIR4; + PAIR4 = {100, 220}; + cout << PAIR4.first << " "; + cout << PAIR4.second << endl; + cout << "//output of comparison operator//" << endl; + + cout + << p1.first << " " << p1.second << endl; + cout << p2.first << " " << p2.second << endl; + cout << p4.first << " " << p4.second << endl; + cout << (p1 == p2) << endl; + cout << (p1 != p2) << endl; + cout << (p1 < p2) << endl; + cout << (p1 > p2) << endl; + cout << (p1 <= p2) << endl; + cout << (p1 >= p2) << endl; + + return 0; } \ No newline at end of file diff --git a/CPP STL/pairs/sorting_pair_arrays.cpp b/CPP STL/pairs/sorting_pair_arrays.cpp index a64692bb..3d7ad634 100644 --- a/CPP STL/pairs/sorting_pair_arrays.cpp +++ b/CPP STL/pairs/sorting_pair_arrays.cpp @@ -1,38 +1,38 @@ -#include -#include -#include -using namespace std; -void sort(int a[], char b[], int n) -{ - pair pa[n]; //pair of array [declartion of size n] - for (int i = 0; i < n; i++) - { - pa[i] = {a[i], b[i]}; - /* - this can we also done by this way - 2nd method:- - - pa[i].first = a[i]; - pa[i].second = b[i]; - */ - - /* - pair will be formed by taking one element from each array - pa={ (10,'x') ,(15,'y'),(5,'z')} - */ - } - sort(pa, pa + n); - for (int i = 0; i < n; i++) - { - cout << pa[i].second << endl; - } -} -int main() -{ - int a[] = {10, 15, 5}; - char b[] = {'x', 'y', 'z'}; - sort(a, b, 3); // it sorts the value according to first value in the pair.... - // array of pair is by-default sorted by the first element - - return 0; -} +#include +#include +#include +using namespace std; +void sort(int a[], char b[], int n) +{ + pair pa[n]; //pair of array [declartion of size n] + for (int i = 0; i < n; i++) + { + pa[i] = {a[i], b[i]}; + /* + this can we also done by this way + 2nd method:- + + pa[i].first = a[i]; + pa[i].second = b[i]; + */ + + /* + pair will be formed by taking one element from each array + pa={ (10,'x') ,(15,'y'),(5,'z')} + */ + } + sort(pa, pa + n); + for (int i = 0; i < n; i++) + { + cout << pa[i].second << endl; + } +} +int main() +{ + int a[] = {10, 15, 5}; + char b[] = {'x', 'y', 'z'}; + sort(a, b, 3); // it sorts the value according to first value in the pair.... + // array of pair is by-default sorted by the first element + + return 0; +} diff --git a/CPP STL/templates/class_template.cpp b/CPP STL/templates/class_template.cpp index b95e5500..708e73c9 100644 --- a/CPP STL/templates/class_template.cpp +++ b/CPP STL/templates/class_template.cpp @@ -1,39 +1,39 @@ -//#include -#include -using namespace std; - -template -struct cordinate -{ - t x, y; - cordinate(t i, t j) //constructor - { - x = i; - y = j; - } - t getfirst() - { - return x; - } - - t getsecond() - { - return y; - } -}; - -//template -// pair::getfirst -// { -// return x; -// } -int main() -{ - cordinate p1(10, 20), p2(99, 89); - cout << p1.getfirst() << " " << p1.getsecond() << endl; - cout << p2.getfirst() << " " << p2.getsecond() << endl; - cordinate p3(10.4, 11.6); - cout << p3.getfirst() << " " << p3.getsecond() << endl; - - return 0; +//#include +#include +using namespace std; + +template +struct cordinate +{ + t x, y; + cordinate(t i, t j) //constructor + { + x = i; + y = j; + } + t getfirst() + { + return x; + } + + t getsecond() + { + return y; + } +}; + +//template +// pair::getfirst +// { +// return x; +// } +int main() +{ + cordinate p1(10, 20), p2(99, 89); + cout << p1.getfirst() << " " << p1.getsecond() << endl; + cout << p2.getfirst() << " " << p2.getsecond() << endl; + cordinate p3(10.4, 11.6); + cout << p3.getfirst() << " " << p3.getsecond() << endl; + + return 0; } \ No newline at end of file diff --git a/CPP STL/templates/functional_temp_part2.cpp b/CPP STL/templates/functional_temp_part2.cpp index edcbcd47..fe24994d 100644 --- a/CPP STL/templates/functional_temp_part2.cpp +++ b/CPP STL/templates/functional_temp_part2.cpp @@ -1,35 +1,35 @@ -#include - -using namespace std; - -//function template with some limit - -template -t arrmax(t arr[], t n) -{ - if (n > limit) - { - cout << "limit exceeded"; - } - else - { - int res = arr[0]; - for (int i = 1; i < n; i++) - { - if (arr[i] > res) - { - res = arr[i]; - } - } - return res; - } - return 0; -} -int main() -{ - int arr[] = {10, 20, 30, 100, 50, 11}; - int x = sizeof(arr) / sizeof(arr[0]); - cout << arrmax(arr, x) << endl; - - return 0; +#include + +using namespace std; + +//function template with some limit + +template +t arrmax(t arr[], t n) +{ + if (n > limit) + { + cout << "limit exceeded"; + } + else + { + int res = arr[0]; + for (int i = 1; i < n; i++) + { + if (arr[i] > res) + { + res = arr[i]; + } + } + return res; + } + return 0; +} +int main() +{ + int arr[] = {10, 20, 30, 100, 50, 11}; + int x = sizeof(arr) / sizeof(arr[0]); + cout << arrmax(arr, x) << endl; + + return 0; } \ No newline at end of file diff --git a/CPP STL/templates/functional_template.cpp b/CPP STL/templates/functional_template.cpp index b844389e..5cea722e 100644 --- a/CPP STL/templates/functional_template.cpp +++ b/CPP STL/templates/functional_template.cpp @@ -1,30 +1,30 @@ -#include - -using namespace std; - -template -t arrmax(t arr[], t n) -{ - t res = arr[0]; - for (int i = 1; i < n; i++) - { - if (arr[i] > res) - { - res = arr[i]; - } - } - return res; -} -int main() -{ - int arr[] = {10, 20, 30, 100, 50, 11}; - int x = sizeof(arr) / sizeof(arr[0]); - cout << arrmax(arr, x)<(arr2, 6)<(arr1, y); - return 0; +#include + +using namespace std; + +template +t arrmax(t arr[], t n) +{ + t res = arr[0]; + for (int i = 1; i < n; i++) + { + if (arr[i] > res) + { + res = arr[i]; + } + } + return res; +} +int main() +{ + int arr[] = {10, 20, 30, 100, 50, 11}; + int x = sizeof(arr) / sizeof(arr[0]); + cout << arrmax(arr, x)<(arr2, 6)<(arr1, y); + return 0; } \ No newline at end of file diff --git a/CPP STL/templates/template_example.cpp b/CPP STL/templates/template_example.cpp index a8f62496..143feaa4 100644 --- a/CPP STL/templates/template_example.cpp +++ b/CPP STL/templates/template_example.cpp @@ -1,20 +1,20 @@ -#include - -#include - -using namespace std; - -//#define int long long - -template //or we can write like this template