Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postorder tree traversal in cpp #262

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
88 changes: 88 additions & 0 deletions String/calandar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <bits/stdc++.h>
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;
}
56 changes: 56 additions & 0 deletions Tree/postorder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <bits/stdc++.h>
using namespace std;

struct Node {
int data;
struct Node *left, *right;
};



void POSTORDER(struct Node* head)
{
struct Node* temp = head;
unordered_set<Node*> 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;
}
23 changes: 23 additions & 0 deletions Vector/vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#include<vector>
int main(){
vector <int> v {10,20,40};
cout<<v[0]<<" ";

vector <string> v1 {"aawesh","patanwala"};
cout<<v1[0]<<" ";

vector <char> v4 {'A','B'};
cout<<v4[0]<<" ";

vector <char> 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<<v3[0]<<" "<<v3[1]<<" "<<v3[2]<<" "<<v3[3]<<" "<<v3[4]<<" "<<endl;
cout<<"ok";
}
34 changes: 34 additions & 0 deletions removeDuplicate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//remove Duplicate
#include<bits/stdc++.h>
using namespace std;

int main(){
int arr[1000], n, i, j;

cin>>n;

for(i=0; i<n; i++){
cin>>arr[i];
}

for(i=0; i<n; i++){
for(j=0; j<n; j++){
if(arr[i] != arr[i+1]){
cout<<arr[i]<<" ";
cout<<arr[j]<<" ";
}
else{
cout<<i<<" ";
}

//i++;
//j++;

}
}

for(i=0; i<n; i++){
cout<<arr[i]<<" ";
}

}