-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77e52bc
commit 96a75e9
Showing
114 changed files
with
1,038 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
char ex[]="abc"; | ||
do{ | ||
|
||
cout<<ex<<endl; | ||
}while(next_permutation(ex,ex+3)); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
|
||
using namespace std; | ||
int main() { | ||
int n, r; | ||
std::cin >> n; | ||
std::cin >> r; | ||
string ex="abcd"; | ||
std::vector<bool> v(n); | ||
std::fill(v.begin(), v.begin() + r, true); | ||
|
||
do { | ||
for (int i = 0; i < n; ++i) { | ||
if (v[i]) { | ||
cout<<ex[i]; | ||
//std::cout << (i + 1) << " "; | ||
} | ||
} | ||
cout<<endl; | ||
std::cout << "\n"; | ||
} while (std::prev_permutation(v.begin(), v.end())); | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// C program to print all permutations with duplicates allowed | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
/* Function to swap values at two pointers */ | ||
void swap(char *x, char *y) | ||
{ | ||
char temp; | ||
temp = *x; | ||
*x = *y; | ||
*y = temp; | ||
} | ||
|
||
/* Function to print permutations of string | ||
This function takes three parameters: | ||
1. String | ||
2. Starting index of the string | ||
3. Ending index of the string. */ | ||
void permute(char *a, int l, int r) | ||
{ | ||
int i; | ||
if (l == r) | ||
printf("%s\n", a); | ||
else | ||
{ | ||
for (i = l; i <= r; i++) | ||
{ | ||
swap((a+l), (a+i)); | ||
permute(a, l+1, r); | ||
swap((a+l), (a+i)); //backtrack | ||
} | ||
} | ||
} | ||
|
||
/* Driver program to test above functions */ | ||
int main() | ||
{ | ||
char str[] = "ABC"; | ||
int n = strlen(str); | ||
permute(str, 0, n-1); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class PeacefulLine{ | ||
public: | ||
string makeLine(vector <int> x){ | ||
int m=-1,ex[26]={}; | ||
for(int i=0;i<x.size();i++){ | ||
ex[x[i]]++; | ||
} | ||
for(int i=0;i<26;i++){ | ||
if(ex[i]>m) | ||
m=ex[i]; | ||
} | ||
int r= x.size()-m*2 ; | ||
if(r >= -1) | ||
return "possible"; | ||
else | ||
return "impossible"; | ||
|
||
} | ||
}; | ||
|
||
int main(){ | ||
|
||
vector <int> x = { | ||
1,2,3,4 | ||
}; | ||
|
||
PeacefulLine t; | ||
cout<< t.makeLine(x)<<endl; | ||
} |
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
8 4 | ||
4 7 | ||
12 12 | ||
24 96 | ||
1000000000 | ||
999999999 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() { | ||
string s(10u, ' '); // Create a string of ten blanks. | ||
|
||
const char* A = "this is a test"; | ||
s += A; | ||
cout<<s<<endl; | ||
cout << "s = " << (s + '\n'); | ||
cout << "As a null-terminated sequence: " << s.c_str() << endl; | ||
cout << "The sixteenth character is " << s[15] << endl; | ||
|
||
reverse(s.begin(), s.end()); | ||
s.push_back('\n'); | ||
string name="Ashik "; | ||
name.pop_back(); | ||
name.pop_back(); | ||
cout<<"|"<<name<<"|"<<endl; | ||
cout << s; | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
template<class T> | ||
struct Node{ | ||
T value; | ||
Node<T>* left; | ||
Node<T>* right; | ||
|
||
Node(T _value){ | ||
value = _value; | ||
left = NULL; | ||
right = NULL; | ||
} | ||
}; | ||
|
||
template<class T> | ||
class BST{ | ||
private: | ||
Node<T>* root; | ||
public: | ||
BST(){ | ||
root = NULL; | ||
} | ||
|
||
void insertHelper(Node<T>* ¤t, T value){ | ||
if(current==NULL){ // We have reached bottom of the tree | ||
// Base case | ||
current = new Node<T>(value); | ||
}else{ | ||
if(value<current->value){ | ||
insertHelper(current->left, value); // going to the left | ||
}else if(value>current->value){ | ||
insertHelper(current->right, value); // going to the right | ||
} | ||
} | ||
} | ||
|
||
void insert(T value){ | ||
if(isEmpty()) root = new Node<T>(value); // tree is empty | ||
else{ | ||
// the tree is not empty | ||
insertHelper(root, value); | ||
} | ||
} | ||
|
||
bool hasHelper(Node<T>* current, T value){ | ||
bool f = false; | ||
if(current!=NULL){ | ||
if(current->value == value) return true; // match found | ||
else{ | ||
if(value<current->value){ // search in the left side | ||
f = hasHelper(current->left, value); | ||
}else{ // search in the right side | ||
f = hasHelper(current->right, value); | ||
} | ||
} | ||
} | ||
return f; | ||
} | ||
|
||
bool has(T value){ | ||
// return true if the value is in the tree, else return false | ||
return hasHelper(root, value); | ||
} | ||
|
||
bool isEmpty(){ | ||
return (root==NULL); | ||
} | ||
|
||
void prefix(Node<T>* current){ | ||
if(current!=NULL){ | ||
cout<<current->value<<" "; | ||
prefix(current->left); | ||
prefix(current->right); | ||
} | ||
} | ||
|
||
void infix(Node<T>* current){ | ||
if(current!=NULL){ | ||
infix(current->left); | ||
cout<<current->value<<" "; | ||
infix(current->right); | ||
} | ||
} | ||
|
||
void postfix(Node<T>* current){ | ||
if(current!=NULL){ | ||
postfix(current->left); | ||
postfix(current->right); | ||
cout<<current->value<<" "; | ||
} | ||
} | ||
|
||
void display(int order=0){ | ||
if(order==0) prefix(root); | ||
else if(order==1) infix(root); | ||
else if(order==2) postfix(root); | ||
cout<<endl; | ||
} | ||
|
||
bool deleteValueHelper(Node<T>* parent, Node<T>* current, T value) { | ||
//cout<<current->value<<endl; | ||
if (!current) return false; | ||
if (current->value == value) { | ||
|
||
//if(current)cout<<"ff"<<current->value<<endl; | ||
if (current->left == NULL || current->right == NULL) { | ||
|
||
Node<T>* temp = current->left; | ||
if (current->right) temp = current->right; | ||
|
||
|
||
if (parent) { | ||
|
||
if (parent->left == current) { | ||
parent->left = temp; | ||
|
||
} else { | ||
parent->right = temp; | ||
} | ||
} else { | ||
root = temp; | ||
} | ||
|
||
|
||
} else { | ||
Node<T>* validSubs = current->right; | ||
while (validSubs->left) { | ||
validSubs = validSubs->left; | ||
} | ||
T temp = current->value; | ||
current->value = validSubs->value; | ||
validSubs->value = temp; | ||
return deleteValueHelper(current, current->right, temp); | ||
} | ||
//if(current)cout<<"ff"<<current->value<<endl; | ||
delete current; | ||
//cout<<parent->left->value<<endl; | ||
return true; | ||
} | ||
if(current->value > value) | ||
return deleteValueHelper(current, current->left, value); | ||
return deleteValueHelper(current, current->right, value); | ||
} | ||
|
||
|
||
bool deleteValue(T value) { | ||
Node<T>* parent=NULL; | ||
return deleteValueHelper(parent, root, value); | ||
} | ||
}; | ||
|
||
|
||
int main(){ | ||
BST<int> firstTree; // We are creating the binary tree, it is empty | ||
//BST<string> tree2; | ||
//BST<double> tree3; | ||
//BST<char> tree4; | ||
//BST<Student> tree5; | ||
//BST<List<int>> tree6; | ||
//List<BST<int>> tree7; | ||
int nums[] = {10, 7, 5, 6, 12, 11, 15}; | ||
int c = 7; | ||
|
||
for(int i=0;i<c;i++){ | ||
firstTree.insert(nums[i]); | ||
} | ||
|
||
firstTree.display(1); | ||
firstTree.deleteValue(15); | ||
firstTree.display(1); | ||
firstTree.deleteValue(5); | ||
firstTree.display(1); | ||
firstTree.deleteValue(10); | ||
firstTree.display(1); | ||
firstTree.deleteValue(7); | ||
firstTree.display(1); | ||
cout<<firstTree.has(999999)<<endl; | ||
|
||
return 0; | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() { | ||
const bitset<12> mask(2730); | ||
cout << "mask = " << mask << endl; | ||
|
||
bitset<12> x(8); | ||
cout<<x.to_ulong()<<endl; | ||
cout << "Enter a 12-bit bitset in binary: "; | ||
if (cin >> x) { | ||
cout << "x = " << x << endl; | ||
cout << "As ulong: " << x.to_ulong() << endl; | ||
cout << "And with mask: " << (x & mask) << endl; | ||
cout << "Or with mask: " << (x | mask) << endl; | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() { | ||
int A[] = { 2, 0, 2, 6, 0, 3, 1, -7 }; | ||
const int N = sizeof(A) / sizeof(int); | ||
|
||
cout << "Number of zeros: " | ||
<< count(A, A + N, 2) | ||
<< endl; | ||
} |
Binary file not shown.
Oops, something went wrong.