diff --git a/Ashu Yadav/Perm of a string.cpp b/Ashu Yadav/Perm of a string.cpp new file mode 100644 index 0000000..ba81d3a --- /dev/null +++ b/Ashu Yadav/Perm of a string.cpp @@ -0,0 +1,35 @@ +//This program will solve the mentioned issue number #72 +//Credits:Ashu Yadav +//Finding all permutation that can be formed by a user entered string. +//Im considering small input string for the current moment of time + +#include +using namespace std; + +void ans(string s,int beg,int end){ + //if the beg and ending index of the string are same in our passed rec fun then print the string + //this is our base case that will stop the rec call + if(beg==end){ + cout<>s; + //length of the string + int len=s.length(); + //our recursive function called + ans(s,0,len-1); + return 0; +} \ No newline at end of file diff --git a/Ashu Yadav/count of pairs.cpp b/Ashu Yadav/count of pairs.cpp new file mode 100644 index 0000000..ce0a4bd --- /dev/null +++ b/Ashu Yadav/count of pairs.cpp @@ -0,0 +1,34 @@ +// We have to count the number of pairs whose sum is divisible by the number pased by the user +//iterative search can give TLE so we will be using another approach here +//Credits:Ashu Yadav + +#include +using namespace std; +//logic +int ans(int a[],int n,int k){ + //array to store remainder + int occ[k]={0}; + //remainder + for(int i=0;i>n; + int a[n]; + for(int i=0;i>a[i]; + int k; + cin>>k; + //ans + cout< +using namespace std; +//Finding the height of the tree +int height(node* node) +{ + //base case to terminate the rec call + if (node == NULL) + return 0; + else + { + int lefth = height(node->left); + int righth = height(node->right); + + if (lefth > righth) + return(lefth + 1); + else return(righth + 1); + } +} +//A node class to define the char of a node +class node +{ + public: + int data; + //pointers for pointing the left subtree and rightsubtree nodes + node* left; + node* right; +}; + +//for making new nodes +node* nnode(int value) +{ + node* Node = new node(); + Node->data = value; + Node->left = NULL; + Node->right = NULL; + + return(Node); +} +int main(){ + //Here we can take the data from the user of can pre define the data + //use "nnode" function to make new node and assigning values to it + + //finally we can call height function defined to get the height of the tree + cout< +using namespace std; +//Char of node +struct Node +{ + int data; + struct Node* left, *right; + Node(int data) + { + this->data = data; + left = right = NULL; + } +}; +//function to print postorder +void Postorder(struct Node *node){ + //base case to terminate rec + if(node==NULL)return; + //left subtree + Postorder(node->left); + //right subtree + Postorder(node->right); + //print data of node + cout<data<<" "; +} + +//function to print preorder +void Preorder(struct Node *node){ + //base case to terminate rec + if(node==NULL)return; + //print data of node + cout<data<<" "; + //left subtree + Preorder(node->left); + //right subtree + Preorder(node->right); +} + +//function to print inorder +void Inorder(struct Node *node){ + //base case to terminate rec + if(node==NULL)return; + //left subtree + Inorder(node->left); + //print data of node + cout<data<<" "; + //right subtree + Inorder(node->right); +} +int main(){ + //Here we can take the data from the user of can pre define the data + //use "nnode" function to make new node and assigning values to it + + //prints preorder traversal + cout<