Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwek authored Feb 9, 2019
2 parents e8fd1df + 9461beb commit 28f2056
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 74 deletions.
4 changes: 3 additions & 1 deletion Datastructures/Linked List.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions Datastructures/Stack Using Array.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include<iostream>
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";
}
Expand Down Expand Up @@ -42,6 +42,9 @@ void topmost()
}
int main()
{
cout<<"\nEnter Size of stack : ";
cin>>size;
stack = new int[size];
int ch, x;
do
{
Expand Down
30 changes: 17 additions & 13 deletions Decimal To Binary.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#include<iostream>
// This function convert decimal to binary number
//
#include <iostream>
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<<binary;
} while (number>0);
cout << "the binary is :";
cout << binary;
cout << endl;
return 0;
}
47 changes: 11 additions & 36 deletions Decimal To Hexadecimal .cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<<HexValues[hexArray[i--]];

cout << endl;
return 0;
}
8 changes: 4 additions & 4 deletions Dynamic Programming/Edit Distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
2 changes: 2 additions & 0 deletions Happy_number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
and this sum turns out to be 1 */
#include <iostream>
using namespace std;

int main()
{
int n,k,s=0,d;
Expand All @@ -23,4 +24,5 @@ int main()
cout << n << " is a happy number" << endl;
else
cout << n << " is not a happy number" << endl;
return 0;
}
2 changes: 1 addition & 1 deletion Others/String Fibonacci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ int main()
cout << n << " th Fibonacci is \n";
fib_Accurate(n);

return 0;
return 0;
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ 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.
* 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.
* Can suggest any change in present algorithms(if needed).
* Can suggest any change in present algorithms(if needed).
38 changes: 27 additions & 11 deletions Sorting/Bubble Sort.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
//Bubble Sort

#include<iostream>
#include<vector>
using namespace std;

int main()
{
int n;
short swap_check=0;
cout << "Enter the amount of numbers to sort: ";
cin >> n;
int Array[n];
cout<<"\nEnter any 6 Numbers for Unsorted Array : ";
vector<int> numbers;
cout << "Enter " << n << " numbers: ";
int num;

//Input
//Input
for(int i=0; i<n; i++)
{
cin>>Array[i];
cin >> num;
numbers.push_back(num);
}

//Bubble Sorting
for(int i=0; i<n; i++)
{
for(int j=0; j<n-1; j++)
swap_check=0;
for(int j=0; j<n-1-i; j++)
{
if(Array[j]>Array[j+1])
if(numbers[j]>numbers[j+1])
{
int temp=Array[j];
Array[j]=Array[j+1];
Array[j+1]=temp;
swap_check=1;
swap(numbers[j], numbers[j+1]);
}
}
if(swap_check == 0)
{
break;
}
}

//Output
cout<<"\nSorted Array : ";
for(int i=0; i<n; i++)
for(int i=0; i<numbers.size(); i++)
{
cout<<Array[i]<<"\t";
if(i != numbers.size() -1)
{
cout << numbers[i] << ", ";
}else
{
cout << numbers[i] << endl;
}
}
return 0;
}
5 changes: 4 additions & 1 deletion Sorting/Insertion Sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 any "<<n<<" Numbers for Unsorted Array : ";

//Input
for(int i=0; i<n; i++)
Expand All @@ -34,5 +36,6 @@ int main()
{
cout<<Array[i]<<"\t";
}
return 0;
}

Empty file removed s[i]
Empty file.

0 comments on commit 28f2056

Please sign in to comment.