mirror of
https://github.com/c0de-archive/hacktoberfest-2018.git
synced 2025-01-03 08:22:39 +00:00
Merge pull request #36 from anksos/contibutions_2018_hackoctober
Added profile on README.md
This commit is contained in:
commit
6800e22bfa
@ -160,6 +160,12 @@ Start adding your names here:
|
|||||||
- Fourth year student in Mechanical Engineering.
|
- Fourth year student in Mechanical Engineering.
|
||||||
- [![github-alt][github-img]](https://github.com/UtkarshKunwar)
|
- [![github-alt][github-img]](https://github.com/UtkarshKunwar)
|
||||||
|
|
||||||
|
### Anastasis Xouzafeiris (aka anksos)
|
||||||
|
- I am a VMware engineer
|
||||||
|
- I'm currently working as a Virtualization Specialist
|
||||||
|
[![twitter-alt][twitter-img]](https://twitter.com/ankso)
|
||||||
|
[![github-alt][github-img]](https://github.com/anksos)
|
||||||
|
|
||||||
### Example Profile
|
### Example Profile
|
||||||
- I'm an example that you can copy, if you want :)
|
- I'm an example that you can copy, if you want :)
|
||||||
- I work for...
|
- I work for...
|
||||||
|
38
code/binary_search-anksos.cs
Normal file
38
code/binary_search-anksos.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// LANGUAGE: C#
|
||||||
|
// TOPIC: Iterative Implementation of binary search algorithm
|
||||||
|
using System;
|
||||||
|
class GFG {
|
||||||
|
// Returns index of x if it is present in arr[],
|
||||||
|
// else return -1
|
||||||
|
static int binarySearch(int []arr, int x) {
|
||||||
|
int l = 0, r = arr.Length - 1;
|
||||||
|
while (l <= r) {
|
||||||
|
int m = l + (r-l)/2;
|
||||||
|
// Check if x is present at mid
|
||||||
|
if (arr[m] == x)
|
||||||
|
return m;
|
||||||
|
// If x greater, ignore left half
|
||||||
|
if (arr[m] < x)
|
||||||
|
l = m + 1;
|
||||||
|
// If x is smaller, ignore right half
|
||||||
|
else
|
||||||
|
r = m - 1;
|
||||||
|
}
|
||||||
|
// if we reach here, then element was
|
||||||
|
// not present
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// Driver method to test above
|
||||||
|
public static void Main() {
|
||||||
|
int []arr = {2, 3, 4, 10, 40};
|
||||||
|
int n = arr.Length;
|
||||||
|
int x = 10;
|
||||||
|
int result = binarySearch(arr, x);
|
||||||
|
if (result == -1)
|
||||||
|
Console.WriteLine("Element not present");
|
||||||
|
else
|
||||||
|
Console.WriteLine("Element found at " +
|
||||||
|
"index " + result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// end of file
|
Loading…
Reference in New Issue
Block a user