File tree 3 files changed +52
-6
lines changed
3 files changed +52
-6
lines changed Original file line number Diff line number Diff line change
1
+ package algorithms ;
2
+
3
+ import java .util .ArrayList ;
4
+
5
+ public class quick extends sorting_algorithm
6
+ {
7
+ public quick ()
8
+ {
9
+ super ();
10
+ }
11
+
12
+ public quick (ArrayList <Integer > source )
13
+ {
14
+ super (source );
15
+ }
16
+
17
+ @ Override
18
+ public ArrayList <Integer > sort_out ()
19
+ {
20
+ sorting_procedure (0 , to_be_sorted .size () - 1 );
21
+
22
+ return to_be_sorted ;
23
+ }
24
+
25
+ void sorting_procedure (int low , int high )
26
+ {
27
+ int pivot = to_be_sorted .get ((low + high ) / 2 );
28
+ int i = low , j = high ;
29
+
30
+ do {
31
+ while (to_be_sorted .get (i ) < pivot ) i ++;
32
+ while (to_be_sorted .get (j ) > pivot ) j --;
33
+ if (i <= j )
34
+ {
35
+ swap (i , j );
36
+ i ++;
37
+ j --;
38
+ }
39
+ } while (i <= j );
40
+
41
+ if (j > low ) sorting_procedure (low , j );
42
+ if (i < high ) sorting_procedure (i , high );
43
+ }
44
+ }
Original file line number Diff line number Diff line change @@ -6,12 +6,12 @@ public abstract class sorting_algorithm
6
6
{
7
7
ArrayList <Integer > to_be_sorted ;
8
8
9
- public sorting_algorithm ()
9
+ sorting_algorithm ()
10
10
{
11
11
this .to_be_sorted = new ArrayList <>();
12
12
}
13
13
14
- public sorting_algorithm (ArrayList <Integer > to_be_sorted )
14
+ sorting_algorithm (ArrayList <Integer > to_be_sorted )
15
15
{
16
16
this .to_be_sorted = new ArrayList <>(to_be_sorted .size ());
17
17
this .to_be_sorted .addAll (to_be_sorted );
Original file line number Diff line number Diff line change 7
7
8
8
public class main
9
9
{
10
- public static Random seed = new Random ();
10
+ static Random seed = new Random ();
11
11
static ArrayList <Integer > randomize_new_array (int size )
12
12
{
13
13
ArrayList <Integer > new_array = new ArrayList <Integer >(size );
@@ -17,9 +17,8 @@ static ArrayList<Integer> randomize_new_array(int size)
17
17
18
18
static void print_array_out (ArrayList <Integer > array )
19
19
{
20
- int size = array .size ();
21
- for (int i = 0 ; i < size ; i ++)
22
- System .out .println (array .get (i ));
20
+ for (Integer integer : array )
21
+ System .out .println (integer );
23
22
24
23
System .out .println ("🧶-----------------------🐈" );
25
24
}
@@ -46,8 +45,11 @@ public static void main(String args[])
46
45
47
46
bubble bubble_sort = new bubble ();
48
47
insert insert_sort = new insert ();
48
+ quick quick_sort = new quick ();
49
49
50
50
System .out .println (estimate_sorting_duration (bubble_sort , tests ));
51
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));
52
54
}
53
55
}
You can’t perform that action at this time.
0 commit comments