forked from ambujraj/hacktoberfest2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 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,44 @@ | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int n, i, arr[50], el, low, high, mid; | ||
cout << "Enter size of list:"; | ||
cin >> n; | ||
cout << "Enter elements :"; | ||
for (i=0; i<n; i++) | ||
{ | ||
cin >> arr[i]; | ||
} | ||
cout << "Enter element to be searched:"; | ||
cin >> el; | ||
low = 0; | ||
high = n-1; | ||
mid = (low+high)/2; | ||
while (low <= high) | ||
{ | ||
if(arr[mid] < el) | ||
{ | ||
low = mid + 1; | ||
|
||
} | ||
else if(arr[mid] == el) | ||
{ | ||
cout << el <<" found at location " << mid <<"\n"; | ||
break; | ||
} | ||
else | ||
{ | ||
high = mid - 1; | ||
} | ||
mid = (low + high)/2; | ||
} | ||
if(low > high) | ||
{ | ||
cout << "Not found! " << el << " is not present in the list."; | ||
} | ||
|
||
return 0; | ||
} |
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 |
---|---|---|
|
@@ -1718,3 +1718,15 @@ Place: Italy | |
About: Junior Software Engineer | ||
Programming Language: C, C++, Java, C#, Python, Scala | ||
Email: [email protected] | ||
|
||
Name : Rahul Mishra | ||
Place : Noida(India) | ||
About : B.Tech(CSE) student | ||
Programming Language : C | ||
Email : [email protected] | ||
|
||
Name : [Trishla Verma](https://github.com/trishla08)<br/> | ||
Place : New Delhi , India <br/> | ||
About : Coding Enthusiast | Computer Engineering Student | ||
Programming Languages : C, C++, Java, Javascript | ||
Email : [email protected] |
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,36 @@ | ||
|
||
/* I will add here every day one or two common js interview questions and there respective answers which would | ||
help u gain confidence and also to ace or hone up your JS skills | ||
*/ | ||
let obj = { | ||
a:5, | ||
b:function(){ | ||
console.log(this.a); | ||
}, | ||
c:()=>{ | ||
console.log(this.a); | ||
} | ||
}; | ||
|
||
let f1 = obj.b; | ||
let f2 = obj.c; | ||
f1(); | ||
f2(); | ||
|
||
obj.b(); | ||
obj.c(); | ||
|
||
|
||
//So, answer of this above four function calling will be as follows with their explanation => | ||
|
||
f1() // this will print "undefined" as in after obj.b, f1 is now referencing global object window not object obj | ||
// this.a will print undefined as with window object there is no a property defined. | ||
f2() // this will also print "undefined" as in arrow functions "this" will refer "this" of surrounding scope | ||
// as in arrow function "this" doesn't not get bind so if we want to know the value of this we should see | ||
// the this just above the line we have start declaring our arrow function.Hence here "this" is referring to | ||
// window object that's why it doesn't has any 'a' property defined with it. | ||
|
||
obj.b() // here it will print '5' as in regular function calling b method will get bind to object left of dot | ||
|
||
obj.c() // here also it will print "undefined" as in arrow function this doesn't get bind and it will see "this" of surrounding scope | ||
// which is referring to window object and that object not have any 'a' property defined with it |