From 210a0d47f48989431ae26c14a4372a2c7169dc42 Mon Sep 17 00:00:00 2001 From: soulzstriker Date: Thu, 2 Aug 2018 17:02:37 +0800 Subject: [PATCH 01/17] Clean up the HTML comments --- Decimal To Binary.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Decimal To Binary.cpp b/Decimal To Binary.cpp index 3794d2a9697..682cb6b0547 100644 --- a/Decimal To Binary.cpp +++ b/Decimal To Binary.cpp @@ -1,20 +1,24 @@ -#include +// This function convert decimal to binary number +// +#include "stdafx.h" +#include using namespace std; + int main() { int number; - cin>>number; - int remainder,binary=0,var=1; - -do{ - - remainder=number%2; - number=number/2; - binary=binary+(remainder*var); - var=var*10; + cout << "Enter a number:"; + cin >> number; + int remainder, binary = 0, var = 1; + do { + remainder = number % 2; + number = number / 2; + binary = binary + (remainder*var); + var = var * 10; -} -while(number>0); - cout<0); + cout << "the binary is :"; + cout << binary; + cout << endl; } From 0e3b07ec479baa0041a3dc656bccb8a25a871536 Mon Sep 17 00:00:00 2001 From: CrazyMerlyn Date: Sun, 16 Sep 2018 16:47:02 +0530 Subject: [PATCH 02/17] Fix bugs in edit distance implementation --- Dynamic Programming/Edit Distance.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dynamic Programming/Edit Distance.cpp b/Dynamic Programming/Edit Distance.cpp index d99d03c5a14..ff0d3fe191c 100644 --- a/Dynamic Programming/Edit Distance.cpp +++ b/Dynamic Programming/Edit Distance.cpp @@ -30,7 +30,7 @@ int editDist(string str1, string str2, int m, int n) { //If last characters are same then continue //for the rest of them. - if(str1[m-1] == str2[n-2]) + if(str1[m-1] == str2[n-1]) return editDist(str1, str2, m-1, n-1); //If last not same, then 3 possibilities @@ -63,7 +63,7 @@ int editDistDP(string str1, string str2, int m, int n) { //If character same. Recur for remaining else if(str1[i-1] == str2[j-1]) - dp[i][j] == dp[i-1][j-1]; + dp[i][j] = dp[i-1][j-1]; else dp[i][j] = 1 + min(dp[i][j-1],//Insert @@ -80,8 +80,8 @@ int main() { string str1 = "sunday"; string str2 = "saturday"; - cout << editDist(str1, str1, str1.length(), str2.length()) << endl; - cout << editDistDP(str1, str1, str1.length(), str2.length()) << endl; + cout << editDist(str1, str2, str1.length(), str2.length()) << endl; + cout << editDistDP(str1, str2, str1.length(), str2.length()) << endl; return 0; } From 4ff86897b1b6f764b8841ab7a372565c37a04dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20Do=C4=9Fan?= Date: Wed, 26 Sep 2018 00:19:09 +0300 Subject: [PATCH 03/17] n is now taken as an input. --- Sorting/Insertion Sort.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sorting/Insertion Sort.cpp b/Sorting/Insertion Sort.cpp index 45e860dded6..f449ecb77a9 100644 --- a/Sorting/Insertion Sort.cpp +++ b/Sorting/Insertion Sort.cpp @@ -6,8 +6,10 @@ using namespace std; int main() { int n; + cout<<"\nEnter the length of your array : "; + cin>>n; int Array[n]; - cout<<"\nEnter any 6 Numbers for Unsorted Array : "; + cout<<"\nEnter the Numbers for Unsorted Array : "; //Input for(int i=0; i Date: Fri, 28 Sep 2018 23:41:01 +0530 Subject: [PATCH 04/17] Added EXIT option and some fine-tunings Added EXIT option in the menu for getting out of the loop and added lines between printing the list and choices for fine-tuning the output. --- Datastructures/Linked List.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Datastructures/Linked List.cpp b/Datastructures/Linked List.cpp index 9319249fd5d..991c7da09f6 100644 --- a/Datastructures/Linked List.cpp +++ b/Datastructures/Linked List.cpp @@ -85,6 +85,7 @@ int main() cout<<"\n2. Delete"; cout<<"\n3. Search"; cout<<"\n4. Print"; + cout<<"\n0. Exit"; cout<<"\n\nEnter you choice : "; cin>>choice; switch (choice) @@ -98,7 +99,8 @@ int main() case 3 : cout<<"\nEnter the element to be searched : "; cin>>x; search(x); break; - case 4 : show(); break; + case 4 : show(); + cout<<"\n"; break; } } while(choice!=0); From f499342869a096161770e9c16b65afff66775e54 Mon Sep 17 00:00:00 2001 From: Vaibhav Gupta Date: Tue, 2 Oct 2018 16:34:16 +0530 Subject: [PATCH 05/17] Optimize bubble sort algorithm -introduced variable 'swap' for 'outer-for-loop' of bubble sort algorithm. If it remains zero after executing inner-loop, it means array is sorted, hence it does not need to run for n^2 times. - 'for(int j=0; j> n; int Array[n]; - cout<<"\nEnter any 6 Numbers for Unsorted Array : "; + cout<<"\nEnter any "<Array[j+1]) { + swap=1; int temp=Array[j]; Array[j]=Array[j+1]; Array[j+1]=temp; } } + if(swap == 0) + { + break; + } } //Output From 485d1b2bb8905639cb4436c59c3f22988197e882 Mon Sep 17 00:00:00 2001 From: Vaibhav Gupta Date: Tue, 2 Oct 2018 17:05:25 +0530 Subject: [PATCH 06/17] solve bus-error (core dumped), run-time error - Run time error on linux. - 'n' is declared but not initialized, neither its value is taken from user. - 'n' contains garbage value, thus throws run time error. --- Sorting/Insertion Sort.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sorting/Insertion Sort.cpp b/Sorting/Insertion Sort.cpp index 45e860dded6..aca8d228fa1 100644 --- a/Sorting/Insertion Sort.cpp +++ b/Sorting/Insertion Sort.cpp @@ -6,8 +6,10 @@ using namespace std; int main() { int n; + cout<<"Enter the number of elements in your array: "; + cin>>n; int Array[n]; - cout<<"\nEnter any 6 Numbers for Unsorted Array : "; + cout<<"\nEnter any "< Date: Thu, 4 Oct 2018 00:58:53 +0530 Subject: [PATCH 07/17] Typo fix in README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e4ad41623d4..a487c9c64ca 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ How you can contribute? See this small guide. * Use the directory structure of the repository. * Please describe your pull requests. -* Don't use **bits/stdc++.h** because this is quite Linux specific and slow down the compiler process. -* Put in comments in your code. -* Avoid **struct** uses instead the **class** keyword. -* Add some test cases in the main-function. \ No newline at end of file +* Don't use **bits/stdc++.h** because this is quite Linux specific and slows down the compiler process. +* Put comments in your code. +* Avoid **struct**. Instead use the **class** keyword. +* Add some test cases in the main-function. From a874772229083efe7240f49446c419596327a0c4 Mon Sep 17 00:00:00 2001 From: Rakesh Date: Tue, 16 Oct 2018 18:04:32 +0530 Subject: [PATCH 08/17] Delete s[i] Redundant file --- s[i] | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 s[i] diff --git a/s[i] b/s[i] deleted file mode 100644 index e69de29bb2d..00000000000 From afe1ff3b6a2e5eb9ca5306c26e31f687e445ac2f Mon Sep 17 00:00:00 2001 From: Rakesh Date: Tue, 16 Oct 2018 18:16:37 +0530 Subject: [PATCH 09/17] Update String Fibonacci.cpp --- Others/String Fibonacci.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Others/String Fibonacci.cpp b/Others/String Fibonacci.cpp index 44d5d574832..8027b966859 100644 --- a/Others/String Fibonacci.cpp +++ b/Others/String Fibonacci.cpp @@ -81,5 +81,5 @@ int main() cout << n << " th Fibonacci is \n"; fib_Accurate(n); - return 0; + return 0; } From 540a2e494a777da7c96436560a0666a944aa85f9 Mon Sep 17 00:00:00 2001 From: Rakesh Date: Tue, 16 Oct 2018 18:18:48 +0530 Subject: [PATCH 10/17] Update Happy_number.cpp --- Happy_number.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Happy_number.cpp b/Happy_number.cpp index f3571ac3495..f8e518403c9 100644 --- a/Happy_number.cpp +++ b/Happy_number.cpp @@ -2,6 +2,7 @@ and this sum turns out to be 1 */ #include using namespace std; + int main() { int n,k,s=0,d; @@ -23,4 +24,5 @@ int main() cout << n << " is a happy number" << endl; else cout << n << " is not a happy number" << endl; + return 0; } From 73fa353b0ab208e8287648d0c5ff6290a854a390 Mon Sep 17 00:00:00 2001 From: Ashwek Swamy <39827514+ashwek@users.noreply.github.com> Date: Tue, 23 Oct 2018 17:47:43 +0530 Subject: [PATCH 11/17] Reduced Lines of code Using a "HexValues" string to store the possible hex values(0-9 A-F). Changed "void main" to "int main" --- Decimal To Hexadecimal .cpp | 47 +++++++++---------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/Decimal To Hexadecimal .cpp b/Decimal To Hexadecimal .cpp index fadddfd74d2..39333ca00f5 100644 --- a/Decimal To Hexadecimal .cpp +++ b/Decimal To Hexadecimal .cpp @@ -2,50 +2,25 @@ using namespace std; -void main(void) -{ +int main(void){ int valueToConvert = 0; //Holds user input int hexArray[8]; //Contains hex values backwards int i = 0; //counter - int lValue = 0; //Last Value of Hex result + char HexValues[] = "0123456789ABCDEF"; cout << "Enter a Decimal Value" << endl; //Displays request to stdout cin >> valueToConvert; //Stores value into valueToConvert via user input - while (valueToConvert > 0) //Dec to Hex Algorithm - { - lValue = valueToConvert % 16; //Gets remainder - valueToConvert = valueToConvert / 16; - hexArray[i] = lValue; //Stores converted values into an array - i++; + while (valueToConvert > 15){ //Dec to Hex Algorithm + hexArray[i++] = valueToConvert % 16; //Gets remainder + valueToConvert /= 16; } + hexArray[i] = valueToConvert; //Gets last value + cout << "Hex Value: "; - while (i > 0) - { - //Displays Hex Letters to stdout - switch (hexArray[i - 1]) { - case 10: - cout << "A"; - break; - case 11: - cout << "B"; - break; - case 12: - cout << "C"; - break; - case 13: - cout << "D"; - break; - case 14: - cout << "E"; - break; - case 15: - cout << "F"; - break; - default: - cout << hexArray[i - 1]; //if not an int 10 - 15, displays int value - } - i--; - } + while (i >= 0) + cout< Date: Tue, 23 Oct 2018 18:01:24 +0530 Subject: [PATCH 12/17] Added Proper Indentation Added proper indentation and using shorthand. --- Decimal To Binary.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Decimal To Binary.cpp b/Decimal To Binary.cpp index 3794d2a9697..4ed1302c0dc 100644 --- a/Decimal To Binary.cpp +++ b/Decimal To Binary.cpp @@ -1,20 +1,17 @@ #include using namespace std; -int main() -{ +int main(){ int number; + cout <<"Enter number to find its binary : "; cin>>number; int remainder,binary=0,var=1; -do{ - - remainder=number%2; - number=number/2; - binary=binary+(remainder*var); - var=var*10; - - -} -while(number>0); + do{ + remainder = number%2; + number /= 2; + binary += (remainder*var); + var *= 10; + }while(number>0); cout< Date: Tue, 23 Oct 2018 18:42:36 +0530 Subject: [PATCH 13/17] Update Bubble Sort.cpp reduced the number of iteration done be inner for loop used for sorting to improve efficiency. --- Sorting/Bubble Sort.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Sorting/Bubble Sort.cpp b/Sorting/Bubble Sort.cpp index c94a45efcb8..7d79f78e76c 100644 --- a/Sorting/Bubble Sort.cpp +++ b/Sorting/Bubble Sort.cpp @@ -3,27 +3,24 @@ #include using namespace std; -int main() -{ - int n; +int main(){ + int n, temp; + cout<<"Enter size of Array = "; cin >> n; - int Array[n]; - cout<<"\nEnter any 6 Numbers for Unsorted Array : "; + int *Array = new int[n]; + cout<<"\nEnter any " < Date: Sat, 27 Oct 2018 21:18:51 +0530 Subject: [PATCH 14/17] Update Stack Using Array.cpp dynamically allocating memory to `stack` according to size given by user as input --- Datastructures/Stack Using Array.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Datastructures/Stack Using Array.cpp b/Datastructures/Stack Using Array.cpp index 944258ed4b0..c5ad146cb40 100644 --- a/Datastructures/Stack Using Array.cpp +++ b/Datastructures/Stack Using Array.cpp @@ -1,12 +1,12 @@ #include using namespace std; -int stack[10]; -int top=0; +int *stack; +int top=0, size; void push(int x) { - if(top==10) + if(top==size) { cout<<"\nOverflow"; } @@ -42,6 +42,9 @@ void topmost() } int main() { + cout<<"\nEnter Size of stack : "; + cin>>size; + stack = new int[size]; int ch, x; do { From 672f9dc57f66495d9784c71fd55d51ac75505902 Mon Sep 17 00:00:00 2001 From: William Grigor Date: Fri, 21 Dec 2018 23:01:52 -0600 Subject: [PATCH 15/17] Bubble Sort now uses vectors --- Sorting/Bubble Sort.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Sorting/Bubble Sort.cpp b/Sorting/Bubble Sort.cpp index c94a45efcb8..01c421314ca 100644 --- a/Sorting/Bubble Sort.cpp +++ b/Sorting/Bubble Sort.cpp @@ -1,19 +1,22 @@ //Bubble Sort #include +#include using namespace std; int main() { int n; + cout << "Enter the amount of numbers to sort: "; cin >> n; - int Array[n]; - cout<<"\nEnter any 6 Numbers for Unsorted Array : "; - + vector numbers; + cout << "Enter " << n << " numbers: "; + int num; //Input for(int i=0; i>Array[i]; + cin >> num; + numbers.push_back(num); } //Bubble Sorting @@ -21,19 +24,23 @@ int main() { for(int j=0; jArray[j+1]) + if(numbers[j]>numbers[j+1]) { - int temp=Array[j]; - Array[j]=Array[j+1]; - Array[j+1]=temp; + swap(numbers[j], numbers[j+1]); } } } //Output cout<<"\nSorted Array : "; - for(int i=0; i Date: Sat, 9 Feb 2019 12:54:49 +0530 Subject: [PATCH 16/17] Update Decimal To Binary.cpp --- Decimal To Binary.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Decimal To Binary.cpp b/Decimal To Binary.cpp index 682cb6b0547..b8eaba1f154 100644 --- a/Decimal To Binary.cpp +++ b/Decimal To Binary.cpp @@ -1,6 +1,5 @@ // This function convert decimal to binary number // -#include "stdafx.h" #include using namespace std; @@ -21,4 +20,5 @@ int main() cout << "the binary is :"; cout << binary; cout << endl; + return 0; } From e18fe9f740565d38bfcd7be443bced220be01f58 Mon Sep 17 00:00:00 2001 From: Ashwek Swamy <39827514+ashwek@users.noreply.github.com> Date: Sat, 9 Feb 2019 13:25:57 +0530 Subject: [PATCH 17/17] Update Bubble Sort.cpp --- Sorting/Bubble Sort.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sorting/Bubble Sort.cpp b/Sorting/Bubble Sort.cpp index aa4930e82e4..fed01bfc55a 100644 --- a/Sorting/Bubble Sort.cpp +++ b/Sorting/Bubble Sort.cpp @@ -8,13 +8,13 @@ int main() { int n; short swap_check=0; - cout << "Enter the amount of numbers to sort: "; + cout << "Enter the amount of numbers to sort: "; cin >> n; vector numbers; cout << "Enter " << n << " numbers: "; int num; - //Input + //Input for(int i=0; i> num;