forked from NITSkmOS/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from SudhanshuMishra8826/master
added linear search implementation in c.
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |