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 585e970

Browse files
Added first step of the QuickSort
1 parent 7630858 commit 585e970

File tree

1 file changed

+35
-0
lines changed
  • src/main/java/br/com/zevolution/algorithms/sorting/quicksort

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package br.com.zevolution.algorithms.sorting.quicksort;
2+
3+
import br.com.zevolution.algorithms.sorting.Product;
4+
5+
public class QuickSort {
6+
7+
public static void main(String[] args) {
8+
9+
Product[] products = {
10+
new Product("iMac", 30000),
11+
new Product("Keyboard", 100),
12+
new Product("iPhone 12 Pro Max Ultra Uou", 10000),
13+
new Product("Mouse", 50),
14+
new Product("Notebook", 3500)
15+
};
16+
17+
getCheapests(products, products.length);
18+
19+
}
20+
21+
private static void getCheapests(Product[] products, int length) {
22+
int cheapest = 0;
23+
24+
for (int current = 0; current < length - 1; current++) {
25+
Product currentProduct = products[current];
26+
if (currentProduct.getPrice() < products[length - 1].getPrice()) {
27+
cheapest++;
28+
}
29+
}
30+
31+
System.out.println(String.format("There are %d cheaper products.", cheapest));
32+
33+
}
34+
35+
}

0 commit comments

Comments
(0)

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