Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit be39429

Browse files
Added function to find the middle of the LinkedList
1 parent 21caaff commit be39429

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1855
-1453
lines changed

‎.idea/.gitignore

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/misc.xml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/modules.xml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/runConfigurations.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/vcs.xml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Algorithms/Searching/BinarySearch.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
package Algorithms.Searching;
2-
3-
/* Binary Search is a Searching algorithm which uses divide and conquer technique
4-
* Complexity => O(log n) Logarithmic
5-
* NOTE :: The Binary Search algorithm works only on sorted data
6-
* TODO:: visit this link for more details => https://www.youtube.com/watch?v=7iE5xNOJET0
7-
* Copy paste link is it's not working */
8-
//testing
9-
public class BinarySearch {
10-
public int binarySearch(int array[], int element, int lb, int ub) {
11-
while (lb < ub) {
12-
int mid = (lb + ub) / 2;
13-
if (array[mid] < element)
14-
lb = mid + 1;
15-
else if (array[mid] > element)
16-
ub = mid - 1;
17-
else
18-
return mid;
19-
}
20-
return -1;
21-
}
22-
}
23-
class BinarySearchMain {
24-
public static void main(String[] args) {
25-
BinarySearch binarySearch = new BinarySearch();
26-
int arr[] = {1, 2, 3, 4, 5, 6, 7, 9, 10};
27-
int element = 5;
28-
System.out.println(binarySearch.binarySearch(arr, element, 0, arr.length));
29-
30-
}
31-
}
1+
package Algorithms.Searching;
2+
3+
/* Binary Search is a Searching algorithm which uses divide and conquer technique
4+
* Complexity => O(log n) Logarithmic
5+
* NOTE :: The Binary Search algorithm works only on sorted data
6+
* TODO:: visit this link for more details => https://www.youtube.com/watch?v=7iE5xNOJET0
7+
* Copy paste link is it's not working */
8+
//testing
9+
public class BinarySearch {
10+
public int binarySearch(int array[], int element, int lb, int ub) {
11+
while (lb < ub) {
12+
int mid = (lb + ub) / 2;
13+
if (array[mid] < element)
14+
lb = mid + 1;
15+
else if (array[mid] > element)
16+
ub = mid - 1;
17+
else
18+
return mid;
19+
}
20+
return -1;
21+
}
22+
}
23+
class BinarySearchMain {
24+
public static void main(String[] args) {
25+
BinarySearch binarySearch = new BinarySearch();
26+
int arr[] = {1, 2, 3, 4, 5, 6, 7, 9, 10};
27+
int element = 5;
28+
System.out.println(binarySearch.binarySearch(arr, element, 0, arr.length));
29+
30+
}
31+
}

‎Algorithms/Searching/LinearSearch.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
package Algorithms.Searching;
2-
3-
/* Linear Search is a searching Algorithm that search a given element in the array
4-
* Complexity => O(n) Linear
5-
* TODO:: you can find more details using this link => https://youtu.be/iGnrCiHPOCg
6-
* try to copy paste the link if it is not working*/
7-
8-
public class LinearSearch {
9-
public int Search(int[] array, int element) {
10-
for (int i = 0; i < array.length; i++) {
11-
if (array[i] == element)
12-
return i;
13-
}
14-
return -1;
15-
}
16-
}
17-
18-
class LinearSearchMain {
19-
public static void main(String[] args) {
20-
LinearSearch linearSearch = new LinearSearch();
21-
int array[] = {1, 5, 7, 69, 78, 6, 9, 5, 59, 65, 7, 9};
22-
int element = 6;
23-
System.out.println(linearSearch.Search(array, element));
24-
}
25-
}
1+
package Algorithms.Searching;
2+
3+
/* Linear Search is a searching Algorithm that search a given element in the array
4+
* Complexity => O(n) Linear
5+
* TODO:: you can find more details using this link => https://youtu.be/iGnrCiHPOCg
6+
* try to copy paste the link if it is not working*/
7+
8+
public class LinearSearch {
9+
public int Search(int[] array, int element) {
10+
for (int i = 0; i < array.length; i++) {
11+
if (array[i] == element)
12+
return i;
13+
}
14+
return -1;
15+
}
16+
}
17+
18+
class LinearSearchMain {
19+
public static void main(String[] args) {
20+
LinearSearch linearSearch = new LinearSearch();
21+
int array[] = {1, 5, 7, 69, 78, 6, 9, 5, 59, 65, 7, 9};
22+
int element = 6;
23+
System.out.println(linearSearch.Search(array, element));
24+
}
25+
}

‎Algorithms/Sorting/BubbleSort.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
package Algorithms.Sorting;
2-
3-
/* Bubble Sort is the technique to sort the data
4-
* Complexity => O(n^2)
5-
* Replace array[j] > array[j + 1] <=> array[j] < array[j + 1] to sort in descending order
6-
* TODO:: visit this link for more => https://www.youtube.com/watch?v=v6hmmfIiKu4 */
7-
8-
import java.util.Arrays;
9-
10-
public class BubbleSort {
11-
public int[] bubbleSort(int[] array) {
12-
for (int i = 0; i < array.length; i++) {
13-
for (int j = 0; j < array.length - i - 1; j++) {
14-
if (array[j] > array[j + 1]) {
15-
int temp = array[j];
16-
array[j] = array[j + 1];
17-
array[j + 1] = temp;
18-
}
19-
}
20-
}
21-
return array;
22-
}
23-
}
24-
25-
class BubbleSortMain {
26-
public static void main(String[] args) {
27-
BubbleSort bubbleSort = new BubbleSort();
28-
int[] arr = {1, 65, 8, 6, 89, 3, 9, 86, 9, 85};
29-
System.out.println(Arrays.toString(bubbleSort.bubbleSort(arr)));
30-
}
31-
}
1+
package Algorithms.Sorting;
2+
3+
/* Bubble Sort is the technique to sort the data
4+
* Complexity => O(n^2)
5+
* Replace array[j] > array[j + 1] <=> array[j] < array[j + 1] to sort in descending order
6+
* TODO:: visit this link for more => https://www.youtube.com/watch?v=v6hmmfIiKu4 */
7+
8+
import java.util.Arrays;
9+
10+
public class BubbleSort {
11+
public int[] bubbleSort(int[] array) {
12+
for (int i = 0; i < array.length; i++) {
13+
for (int j = 0; j < array.length - i - 1; j++) {
14+
if (array[j] > array[j + 1]) {
15+
int temp = array[j];
16+
array[j] = array[j + 1];
17+
array[j + 1] = temp;
18+
}
19+
}
20+
}
21+
return array;
22+
}
23+
}
24+
25+
class BubbleSortMain {
26+
public static void main(String[] args) {
27+
BubbleSort bubbleSort = new BubbleSort();
28+
int[] arr = {1, 65, 8, 6, 89, 3, 9, 86, 9, 85};
29+
System.out.println(Arrays.toString(bubbleSort.bubbleSort(arr)));
30+
}
31+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /