Skip to content

Commit 83fabee

Browse files
committed
implemented select sort
1 parent fc5e1e7 commit 83fabee

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package algorithms;
2+
3+
import java.util.ArrayList;
4+
5+
public class select extends sorting_algorithm
6+
{
7+
public select()
8+
{
9+
super();
10+
}
11+
12+
public select(ArrayList<Integer> source)
13+
{
14+
super(source);
15+
}
16+
17+
@Override
18+
public ArrayList<Integer> sort_out()
19+
{
20+
for (int i = to_be_sorted.size(); i >= 2; i--)
21+
{
22+
int max = max_element_index(i);
23+
if (max != i - 1)
24+
swap(i - 1, max);
25+
}
26+
27+
return to_be_sorted;
28+
}
29+
30+
int max_element_index(int limit)
31+
{
32+
int max = 0;
33+
for (int i = 1; i < limit; i++)
34+
if (to_be_sorted.get(i) > to_be_sorted.get(max))
35+
max = i;
36+
return max;
37+
}
38+
}

searching_methods/src/testing/main.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,20 @@ static float estimate_sorting_duration(sorting_algorithm algorithm, ArrayList<Ar
3737

3838
public static void main(String args[])
3939
{
40-
int number_of_tests = 10, test_size = 1900;
41-
ArrayList<ArrayList<Integer>> tests = new ArrayList<ArrayList<Integer>>(number_of_tests);
40+
int number_of_tests = 10, test_size = 10000;
41+
ArrayList<ArrayList<Integer>> set_of_tests = new ArrayList<ArrayList<Integer>>(number_of_tests);
4242

4343
for (int i = 0; i < number_of_tests; i++)
44-
tests.add(randomize_new_array(test_size));
44+
set_of_tests.add(randomize_new_array(test_size));
4545

4646
bubble bubble_sort = new bubble();
4747
insert insert_sort = new insert();
48+
select select_sort = new select();
4849
quick quick_sort = new quick();
4950

50-
System.out.println(estimate_sorting_duration(bubble_sort, tests));
51-
System.out.println(estimate_sorting_duration(insert_sort, tests));
52-
System.out.println(estimate_sorting_duration(quick_sort, tests));
53-
// System.out.println(estimate_sorting_duration(quick_sort, tests));
51+
System.out.println(estimate_sorting_duration(bubble_sort, set_of_tests) + " [ms]");
52+
System.out.println(estimate_sorting_duration(insert_sort, set_of_tests) + " [ms]");
53+
System.out.println(estimate_sorting_duration(select_sort, set_of_tests) + " [ms]");
54+
System.out.println(estimate_sorting_duration(quick_sort, set_of_tests) + " [ms]");
5455
}
5556
}

0 commit comments

Comments
 (0)