diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..a686f22 Binary files /dev/null and b/.DS_Store differ diff --git a/code/.DS_Store b/code/.DS_Store new file mode 100644 index 0000000..ff1ed84 Binary files /dev/null and b/code/.DS_Store differ diff --git a/code/Cpp/Permutations_of_string.cpp b/code/Cpp/Permutations_of_string.cpp new file mode 100644 index 0000000..917cc4f --- /dev/null +++ b/code/Cpp/Permutations_of_string.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +using namespace std; + +void perm(string str, vector &arr){ + if(str.size()==1){ + arr.push_back(str); + return; + } + + char ch = str.back(); + str.pop_back(); + + perm(str, arr); + int len = arr.size(); + for(int i=0; i< len; i++){ + string x = arr[0]; + arr.erase(arr.begin()); + for(int i=0; i<= x.size(); i++){ + string w = x; + w.insert(w.begin() + i, ch); + arr.push_back(w); + } + + } + +} + +int main(){ + string s; + cout << "Enter the string:" << endl; + cin >> s; + vector arr; + perm(s, arr); + + cout << "the permutations are:" << endl; + for(int i=0; i< arr.size(); i++){ + cout << arr[i] << endl; + } +} diff --git a/code/Cpp/mergeSort.cpp b/code/Cpp/mergeSort.cpp new file mode 100644 index 0000000..b8e736f --- /dev/null +++ b/code/Cpp/mergeSort.cpp @@ -0,0 +1,44 @@ +#include +using namespace std; + +void mergeSort(int *input, int size){ + // Write your code here + int temp; + int len1=size/2; + int len2=size-len1; + + + if(size<=1){ + return ; + } + + mergeSort(input, len1); + mergeSort(input+len1, len2); + + for(int j=0; j<=len1; j++){ + for(int i=0; iinput[i+1]){ + temp=input[i]; + input[i]=input[i+1]; + input[i+1]=temp; + + } +} + } + return; + + + } + +int main() { + int input[1000],length; + cin >> length; + for(int i=0; i < length; i++) + cin >> input[i]; + mergeSort(input, length); + for(int i = 0; i < length; i++) { + cout << input[i] << " "; + } +} + + diff --git a/code/Cpp/quickSort.cpp b/code/Cpp/quickSort.cpp new file mode 100644 index 0000000..01dd2a6 --- /dev/null +++ b/code/Cpp/quickSort.cpp @@ -0,0 +1,70 @@ +#include +using namespace std; + +int partition(int input[], int size){ + int x=input[0]; + int count=0; + for(int i=1; icount){ + if(input[i]<=x){ + i++; + } + if(input[j]>x){ + j--; + } + else if(input[i]>x && input[j]<=x){ + int temp=input[i]; + input[i]=input[j]; + input[j]=temp; + i++; + j--; + } + } + return count; +} + +void quickSort(int input[], int size) { + /* Don't write main(). + Don't read input, it is passed as function argument. + Change in the given array itself. + Taking input and printing output is handled automatically. + */ + if(size<=1){ + return; + } + + int count=partition(input, size); + quickSort(input, count); + quickSort(input+count+1, size-count-1); + } + +int main(){ + int n; + cin >> n; + + int *input = new int[n]; + + for(int i = 0; i < n; i++) { + cin >> input[i]; + } + + quickSort(input, n); + for(int i = 0; i < n; i++) { + cout << input[i] << " "; + } + + delete [] input; + +} + + + diff --git a/code/addInfo.json b/code/addInfo.json index 7bd9948..66106cd 100644 --- a/code/addInfo.json +++ b/code/addInfo.json @@ -10,6 +10,12 @@ "place":"Ghaziabad" }, { + + "name":"Sneha Aggarwal", + "age": 20, + "place":"Delhi" + } + "name":"", "age": , "place":"" @@ -20,5 +26,6 @@ "place": "Delhi" } + ]