Skip to content

Commit

Permalink
Merge pull request #2 from SudhanshuMishra8826/master
Browse files Browse the repository at this point in the history
added linear search implementation in c.
  • Loading branch information
tanseersaji authored Oct 5, 2018
2 parents c513b30 + 2f1a008 commit 7c4d0f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bubble_sort/Python/bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def bubbleSort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1] :
arr[j], arr[j+1] = arr[j+1], arr[j]
arr = [64, 34, 25, 12, 22, 11, 90]
bubbleSort(arr)
print ("Sorted array is:")
for i in range(len(arr)):
print ("%d" %arr[i]),
24 changes: 24 additions & 0 deletions linear_search/C/linear search.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
void main()
{
int a[10], i, item,n,flag=0;
printf("Enter number of elements : ");
scanf("%d",&n);
printf("\nEnter elements of an array:\n");
for (i=0; i<n; i++)
{printf("Element : ");
scanf("%d", &a[i]);}
printf("\nEnter item to search: ");
scanf("%d", &item);
for (i=0; i<n; i++)
{
if (item == a[i])
{ flag=1;
printf("\nItem found at location %d", i+1);
break;
}
}
if (flag==0)
printf("\nItem does not exist.");
getch();
}

0 comments on commit 7c4d0f0

Please sign in to comment.