Skip to content

Commit 6d18d04

Browse files
authored
Merge branch 'master' into master
2 parents 12aa235 + 10454b9 commit 6d18d04

4 files changed

Lines changed: 38 additions & 25 deletions

File tree

BinarySearch/C++/BinarySearch-(iterative).cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int binarySearch(int low,int high,int key)
1111
{
1212
while(low<=high)
1313
{
14-
int mid = (low + high) / 2;
14+
int mid = low+(high-low)/2;
1515
if(a[mid] < key)
1616
{
1717
low = mid + 1;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "string.h"
2+
3+
int HammingDistance(char *str1, char *str2){
4+
int i;
5+
int dist = 0;
6+
7+
if(str1 == NULL || str2 == NULL){
8+
return -1;
9+
}
10+
if(strlen(str1) != strlen(str2)){
11+
/*Strings must have the same length*/
12+
return -1;
13+
}
14+
15+
for(i = 0; i < strlen(str1); i++){
16+
if(str1[i] != str2[i]){
17+
dist++;
18+
}
19+
}
20+
21+
return dist;
22+
}

LinearSearch/C/LinearSearch.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1+
#include "stdlib.h"
2+
int LinearSearch(int *array, int len, int key){
3+
int i;
14

2-
#include <stdio.h>
3-
4-
int main()
5-
{
6-
int array[100] search, c, n=10; // n is the number of elements to be stored.
7-
8-
int array[n]; //array[] is used to store the element
9-
10-
printf("Enter the number to search\n");
11-
scanf("%d", &search);
12-
13-
for (c = 0; c < n; c++)
14-
{
15-
if (array[c] == search) /* if required element found */
16-
{
17-
printf("%d is present at location %d.\n", search, c+1);
18-
break;
19-
}
20-
}
21-
if (c == n)
22-
printf("%d is not present in array.\n", search);
23-
24-
return 0;
5+
if(array == NULL){
6+
return -1;
7+
}
8+
9+
for(i = 0; i < len; i++){
10+
if(array[i] == key){
11+
return i;
12+
}
13+
}
14+
15+
return -1;
2516
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Fibonacci | :+1: | :+1: | | :+1: | | | :+1: | | :+1:
2727
FisherYatesShuffle | :+1: | | | | :+1: | :+1: | | :+1: |
2828
Floyd'sAlgorithm | :+1: | :+1: | | | :+1: | | | |
2929
GreatestCommonDivisor | :+1: | | :+1: | :+1: | :+1: | | | |
30-
HammingDistance | :+1: | :+1: | | | | :+1: | | |
30+
HammingDistance | :+1: | :+1: | | :+1: | | :+1: | | |
3131
HeapSort | :+1: | :+1: | | | :+1: | :+1: | :+1: | | :+1:
3232
HistogramEqualization | :+1: | | | | | | | |
3333
InsertionSort | :+1: | :+1: | :+1: | :+1: | :+1: | | :+1: | :+1: |

0 commit comments

Comments
 (0)