From 322d4fddcf67df2b45f7dcb4c0a02a9f37bc69a9 Mon Sep 17 00:00:00 2001 From: Md Aawesh Md Yunus Patanwala Date: Sun, 3 Oct 2021 10:12:51 +0530 Subject: [PATCH 1/4] postorder tree traversal in cpp --- Tree/postorder.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Tree/postorder.cpp diff --git a/Tree/postorder.cpp b/Tree/postorder.cpp new file mode 100644 index 0000000..febeef1 --- /dev/null +++ b/Tree/postorder.cpp @@ -0,0 +1,56 @@ +#include +using namespace std; + +struct Node { + int data; + struct Node *left, *right; +}; + + + +void POSTORDER(struct Node* head) +{ + struct Node* temp = head; + unordered_set visited; + while (temp && visited.find(temp) == visited.end()) { + + + if (temp->left && + visited.find(temp->left) == visited.end()) + temp = temp->left; + + else if (temp->right && + visited.find(temp->right) == visited.end()) + temp = temp->right; + + else { + printf("%d ", temp->data); + visited.insert(temp); + temp = head; + } + } +} + +struct Node* newNode(int data) +{ + struct Node* node = new Node; + node->data = data; + node->left = NULL; + node->right = NULL; + return (node); +} + +int main() +{ + struct Node* root = newNode(8); + root->left = newNode(2); + root->right = newNode(9); + root->left->left = newNode(3); + root->left->right = newNode(5); + root->left->right->left = newNode(6); + root->left->right->right = newNode(4); + root->right->right = newNode(7); + root->right->right->left = newNode(13); + POSTORDER(root); + return 0; +} From 8ca45d2866e469e387f28d0d581b8400b6e99063 Mon Sep 17 00:00:00 2001 From: Md Aawesh Md Yunus Patanwala Date: Sun, 3 Oct 2021 10:28:46 +0530 Subject: [PATCH 2/4] Calander program in cpp --- String/calandar.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 String/calandar.cpp diff --git a/String/calandar.cpp b/String/calandar.cpp new file mode 100644 index 0000000..a907ebd --- /dev/null +++ b/String/calandar.cpp @@ -0,0 +1,88 @@ +#include +using namespace std; + +class Calender{ + public : + int month, year; + + Calender(int mo, int yr){ + month = mo; + year = yr; + } + + // Calender(){ + + // } + void Print_Month(){ + PrintMonth(month, year); + } + int GetDays(int month, int year){ + if( month == 2){ + if((year % 400==0) || (year % 4 == 0 && year % 100 != 0)) + return 29; + else + return 28; + } + + else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 ||month == 10 || month==12) + return 31; + else + return 30; + } + + int MonthStartsOn(int mnth, int yr){ + return 6; + } + + void PrintMonth(int mnth, int yr){ + int date = MonthStartsOn(mnth, yr), i, j, k; + int days = GetDays(mnth, yr); + char c = ' '; + cout << "Mon" << " " << "Tue" << " " << "Wed" << " " << "Thu" << " " << "Fri" << " " << "Sat" << " " << "Sun" << endl; + k = 1; + for(i = 0; i < 7; i ++){ + if(i < date){ + cout << c << c << c << c; + } + else{ + cout << k++ << c << c << c; + } + } + + cout << endl; + k = 8 - date; + while(k < 10){ + for(i = 0; i < 7; i ++){ + if(k > 9) + break; + cout << k << c << c << c; + k ++; + } + if(i == 7) + cout << endl; + } + while(i != 7){ + cout << k << c << c; + k ++; + i ++; + } + cout << endl; + while(k <= days){ + for(i = 0; i < 7; i ++){ + if(k > days) + break; + cout << k << c << c; + k ++; + } + cout << endl; + } + } +}; + + +int main(){ + Calender c; + c.PrintMonth(7, 2020); + + return 0; +} \ No newline at end of file From 47a66deb6e52e233ec7fa23260d99d71c636a3fd Mon Sep 17 00:00:00 2001 From: Md Aawesh Md Yunus Patanwala Date: Sun, 3 Oct 2021 10:31:23 +0530 Subject: [PATCH 3/4] Remove Duplicate program in cpp --- removeDuplicate.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 removeDuplicate.cpp diff --git a/removeDuplicate.cpp b/removeDuplicate.cpp new file mode 100644 index 0000000..23827eb --- /dev/null +++ b/removeDuplicate.cpp @@ -0,0 +1,34 @@ +//remove Duplicate +#include +using namespace std; + +int main(){ + int arr[1000], n, i, j; + + cin>>n; + + for(i=0; i>arr[i]; + } + + for(i=0; i Date: Sun, 3 Oct 2021 10:32:53 +0530 Subject: [PATCH 4/4] Vector Implementation in cpp --- Vector/vector.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Vector/vector.cpp diff --git a/Vector/vector.cpp b/Vector/vector.cpp new file mode 100644 index 0000000..287fad7 --- /dev/null +++ b/Vector/vector.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +#include +#include +int main(){ + vector v {10,20,40}; + cout< v1 {"aawesh","patanwala"}; + cout< v4 {'A','B'}; + cout< v3 {5}; //created a vector of size 5, type char + v3[0] = 'A'; + v3[1] = 'B'; + v3[2] = 'C'; + v3[3] = 'D'; + v3[4] = 'E'; + cout<