Skip to content

Commit 1792582

Browse files
authored
Merge branch 'eugenp:master' into spring-web-test1
2 parents aefdc55 + ed7d817 commit 1792582

File tree

1,864 files changed

+22067
-3352
lines changed

Some content is hidden

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

1,864 files changed

+22067
-3352
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
If you are getting an error while cloning the repository, try running:
44
git config --global http.postBuffer 5000000
55

6-
This will increase the size of the buffer from the default 1MiB to 5MiB.
6+
This will increase the buffer size from the default 1MiB to 5MiB.
77

88
To revert this value to the default, use:
99
git config --global http.postBuffer 1000000
@@ -27,18 +27,18 @@ The Courses
2727
Java and Spring Tutorials
2828
================
2929

30-
This project is **a collection of small and focused tutorials** - each covering a single and well defined area of development in the Java ecosystem.
31-
A strong focus of these is, of course, the Spring Framework - Spring, Spring Boot and Spring Security.
32-
In addition to Spring, the modules here cover a number of aspects of Java.
30+
This project is **a collection of small and focused tutorials** - each covering a single and well-defined area of development in the Java ecosystem.
31+
A strong focus of these is the Spring Framework - Spring, Spring Boot and Spring Security.
32+
In addition to Spring, the modules here cover several aspects of Java.
3333

34-
Profile based segregation
34+
Profile-based segregation
3535
====================
3636

37-
We are using maven build profiles to segregate the huge list of individual projects we have in our repository.
37+
We use Maven build profiles to segregate the huge list of individual projects in our repository.
3838

3939
The projects are broadly divided into 4 lists: default, default-jdk17, default-jdk8 and default-heavy.
4040

41-
Next, they are segregated further on the basis of the tests that we want to execute.
41+
Next, they are segregated further based on the tests that we want to execute.
4242

4343
We also have a parents profile to build only parent modules.
4444

@@ -48,8 +48,8 @@ Therefore, we have a total of 9 profiles:
4848
|--------------------|-----------------------------|------------------------------|
4949
| default | JDK21 projects | *UnitTest |
5050
| integration | JDK21 projects | *IntegrationTest |
51-
| default-jdk17 | JDK17 and above projects | *UnitTest |
52-
| integration-jdk17 | JDK17 and above projects | *IntegrationTest |
51+
| default-jdk17 | JDK17 projects | *UnitTest |
52+
| integration-jdk17 | JDK17 projects | *IntegrationTest |
5353
| profile-jdk22 | JDK22 projects | *UnitTest & *IntegrationTest |
5454
| profile-jdk23 | JDK23 projects | *UnitTest & *IntegrationTest |
5555
| default-heavy | Heavy/long running projects | *UnitTest |

algorithms-modules/algorithms-miscellaneous-9/src/main/java/com/baeldung/algorithms/kthlargest/FindKthLargest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@ public int findKthLargestBySorting(Integer[] arr, int k) {
1212
return arr[targetIndex];
1313
}
1414

15+
public int findSecondLargestWithoutSorting(Integer[] arr) throws Exception{
16+
Integer[] result = new Integer[2];
17+
18+
if (arr == null || arr.length < 2) {
19+
throw new Exception(
20+
"Array should have at least two elements and be not null");
21+
} else {
22+
if (arr[0] > arr[1]) {
23+
result[0] = arr[0];
24+
result[1] = arr[1];
25+
} else {
26+
result[0] = arr[1];
27+
result[1] = arr[0];
28+
}
29+
if (arr.length > 2) {
30+
for (int i = 2; i < arr.length; i++) {
31+
if (arr[i] > result[0]) {
32+
result[1] = result[0];
33+
result[0] = arr[i];
34+
35+
} else if (arr[i] > result[1]) {
36+
result[1] = arr[i];
37+
}
38+
}
39+
}
40+
}
41+
42+
return result[1];
43+
}
44+
1545
public int findKthLargestBySortingDesc(Integer[] arr, int k) {
1646
Arrays.sort(arr, Collections.reverseOrder());
1747
return arr[k - 1];

algorithms-modules/algorithms-miscellaneous-9/src/test/java/com/baeldung/algorithms/kthlargest/FindKthLargestUnitTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public void setup() {
1515
findKthLargest = new FindKthLargest();
1616
}
1717

18+
@Test
19+
void givenIntArray_whenFindSecondLargestWithoutSorting_thenGetResult() throws Exception {
20+
assertThat(findKthLargest.findSecondLargestWithoutSorting(arr)).isEqualTo(9);
21+
}
22+
1823
@Test
1924
void givenIntArray_whenFindKthLargestBySorting_thenGetResult() {
2025
int k = 3;
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
### Relevant Articles:
22

33
- [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers)
4-
- [Guide to In-Place Sorting Algorithm Works with a Java Implementation](https://www.baeldung.com/java-in-place-sorting)
54
- [Partitioning and Sorting Arrays with Many Repeated Entries with Java Examples](https://www.baeldung.com/java-sorting-arrays-with-repeated-entries)
6-
- [Gravity/Bead Sort in Java](https://www.baeldung.com/java-gravity-bead-sort)
75
- [Selection Sort in Java](https://www.baeldung.com/java-selection-sort)
86
- [Bubble Sort in Java](https://www.baeldung.com/java-bubble-sort)
97
- [Insertion Sort in Java](https://www.baeldung.com/java-insertion-sort)
108
- [Heap Sort in Java](https://www.baeldung.com/java-heap-sort)
119
- [Counting Sort in Java](https://www.baeldung.com/java-counting-sort)
1210
- [Radix Sort in Java](https://www.baeldung.com/java-radix-sort)
13-
- More articles: [[<-- prev]](/algorithms-modules/algorithms-sorting)
11+
- More articles: [[<-- prev]](/algorithms-modules/algorithms-sorting)[[next -->]](/algorithms-modules/algorithms-sorting-3)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Relevant Articles:
2+
3+
- [Bucket Sort in Java](https://www.baeldung.com/java-bucket-sort)
4+
- [Shell Sort in Java](https://www.baeldung.com/java-shell-sort)
5+
- [Gravity/Bead Sort in Java](https://www.baeldung.com/java-gravity-bead-sort)
6+
- [Guide to In-Place Sorting Algorithm Works with a Java Implementation](https://www.baeldung.com/java-in-place-sorting)
7+
- More articles: [[<-- prev]](/algorithms-modules/algorithms-sorting-2)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>algorithms-sorting-3</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<name>algorithms-sorting-3</name>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>algorithms-modules</artifactId>
13+
<version>1.0.0-SNAPSHOT</version>
14+
</parent>
15+
16+
<dependencies>
17+
</dependencies>
18+
19+
</project>

0 commit comments

Comments
 (0)