diff --git a/Datastructures/Linked List.cpp b/Datastructures/Linked List.cpp index 9319249fd..991c7da09 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); diff --git a/Decimal To Binary.cpp b/Decimal To Binary.cpp index 4ed1302c0..b8eaba1f1 100644 --- a/Decimal To Binary.cpp +++ b/Decimal To Binary.cpp @@ -1,17 +1,24 @@ -#include +// This function convert decimal to binary number +// +#include using namespace std; -int main(){ - int number; - cout <<"Enter number to find its binary : "; - cin>>number; - int remainder,binary=0,var=1; - do{ - remainder = number%2; - number /= 2; - binary += (remainder*var); - var *= 10; - }while(number>0); - cout<> 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 << "the binary is :"; + cout << binary; + cout << endl; return 0; } diff --git a/Dynamic Programming/Edit Distance.cpp b/Dynamic Programming/Edit Distance.cpp index d99d03c5a..ff0d3fe19 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; } diff --git a/Happy_number.cpp b/Happy_number.cpp index f3571ac34..f8e518403 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; } diff --git a/Others/String Fibonacci.cpp b/Others/String Fibonacci.cpp index 44d5d5748..8027b9668 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; } diff --git a/README.md b/README.md index e4ad41623..a487c9c64 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. diff --git a/Sorting/Bubble Sort.cpp b/Sorting/Bubble Sort.cpp index 7d79f78e7..fed01bfc5 100644 --- a/Sorting/Bubble Sort.cpp +++ b/Sorting/Bubble Sort.cpp @@ -1,35 +1,55 @@ //Bubble Sort #include +#include using namespace std; -int main(){ - int n, temp; - cout<<"Enter size of Array = "; +int main() +{ + int n; + short swap_check=0; + cout << "Enter the amount of numbers to sort: "; cin >> n; - int *Array = new int[n]; - cout<<"\nEnter any " < numbers; + cout << "Enter " << n << " numbers: "; + int num; - //Input - for(int i=0; i>n; int Array[n]; - cout<<"\nEnter any 6 Numbers for Unsorted Array : "; + cout<<"\nEnter any "<