From da4a4010b7c21b472cdf1fa479da93fcd4d84f65 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 1 Oct 2020 17:15:00 +0530 Subject: [PATCH 1/4] check Balance Pranthesis Program added --- Queue/checkBalanceParanthesis.cpp | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Queue/checkBalanceParanthesis.cpp diff --git a/Queue/checkBalanceParanthesis.cpp b/Queue/checkBalanceParanthesis.cpp new file mode 100644 index 0000000..7dd8e3c --- /dev/null +++ b/Queue/checkBalanceParanthesis.cpp @@ -0,0 +1,48 @@ +/* + C++ Program to check for balanced parentheses in an expression using stack. + Given an expression as string comprising of opening and closing characters + of parentheses - (), curly braces - {} and square brackets - [], we need to + check whether symbols are balanced or not. +*/ +#include +#include +#include +using namespace std; +// Function to check whether two characters are opening +// and closing of same type. +bool ArePair(char opening,char closing) +{ + if(opening == '(' && closing == ')') return true; + else if(opening == '{' && closing == '}') return true; + else if(opening == '[' && closing == ']') return true; + return false; +} +bool AreParanthesesBalanced(string exp) +{ + stack S; + for(int i =0;i>expression; + if(AreParanthesesBalanced(expression)) + cout<<"Balanced\n"; + else + cout<<"Not Balanced\n"; +} \ No newline at end of file From 67a7b339052869135aefbb261ce84e6b56b83821 Mon Sep 17 00:00:00 2001 From: Aditya Ranjan <57028840+adityaranjan182@users.noreply.github.com> Date: Tue, 6 Oct 2020 13:01:06 +0530 Subject: [PATCH 2/4] merge all overlapping intervals --- Practice Questions/arrays/merge.cpp | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Practice Questions/arrays/merge.cpp diff --git a/Practice Questions/arrays/merge.cpp b/Practice Questions/arrays/merge.cpp new file mode 100644 index 0000000..ccf4b75 --- /dev/null +++ b/Practice Questions/arrays/merge.cpp @@ -0,0 +1,35 @@ +//sort an array of three types of element 0's, 1's and 2's with linear time and const extra space + +#include +using namespace std; + +void Segregate(int arr[], int n){ + int low = 0, mid = 0, high = n-1; + while(mid<=high){ + switch (arr[mid]){ + case 0: swap(arr[low], arr[mid]); + low++;mid++; + break; + case 1: mid++; + break; + case 2: swap(arr[mid],arr[high]); + high--; mid++; + break; + } + } +} + +int main(){ + int T; + cin>>T; + while(T--){ + int n; + cin>>n; + int arr[n]; + for(int i=0;i>arr[i]; + } + Segregate(arr,n); + for(int i=0;i Date: Thu, 8 Oct 2020 13:55:57 +0530 Subject: [PATCH 3/4] #hactoberfest2020 --- Arrays/BasicArrayOperations/String example.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Arrays/BasicArrayOperations/String example.cpp diff --git a/Arrays/BasicArrayOperations/String example.cpp b/Arrays/BasicArrayOperations/String example.cpp new file mode 100644 index 0000000..17ebb18 --- /dev/null +++ b/Arrays/BasicArrayOperations/String example.cpp @@ -0,0 +1,8 @@ +#include +using namespace std; +int main() +{ + char str[]={'g','f','g'}; + cout< Date: Fri, 23 Oct 2020 11:31:24 +0530 Subject: [PATCH 4/4] Create Juggling_Algo.(Array_Rotation).cpp This algorithm helps to rotate an array --- Arrays/Juggling_Algo.(Array_Rotation).cpp | 60 +++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Arrays/Juggling_Algo.(Array_Rotation).cpp diff --git a/Arrays/Juggling_Algo.(Array_Rotation).cpp b/Arrays/Juggling_Algo.(Array_Rotation).cpp new file mode 100644 index 0000000..6ece7d9 --- /dev/null +++ b/Arrays/Juggling_Algo.(Array_Rotation).cpp @@ -0,0 +1,60 @@ +// C++ program to rotate an array by +// d elements +#include +using namespace std; + +/*Fuction to get gcd of a and b*/ +int gcd(int a, int b) +{ + if (b == 0) + return a; + + else + return gcd(b, a % b); +} + +/*Function to left rotate arr[] of siz n by d*/ +void leftRotate(int arr[], int d, int n) +{ + /* To handle if d >= n */ + d = d % n; + int g_c_d = gcd(d, n); + for (int i = 0; i < g_c_d; i++) { + /* move i-th values of blocks */ + int temp = arr[i]; + int j = i; + + while (1) { + int k = j + d; + if (k >= n) + k = k - n; + + if (k == i) + break; + + arr[j] = arr[k]; + j = k; + } + arr[j] = temp; + } +} + +// Function to print an array +void printArray(int arr[], int size) +{ + for (int i = 0; i < size; i++) + cout << arr[i] << " "; +} + +/* Driver program to test above functions */ +int main() +{ + int arr[] = { 1, 2, 3, 4, 5, 6, 7 }; + int n = sizeof(arr) / sizeof(arr[0]); + + // Function calling + leftRotate(arr, 2, n); + printArray(arr, n); + + return 0; +}