44 *
55 * @author kdgyun
66 *
7- * @version 1.0 .0
7+ * @version 1.1 .0
88 * @since 1.0.0
99 *
1010 * {@link https://st-lab.tistory.com}
1414
1515import java .util .Comparator ;
1616
17+ import Utils .Convert ;
18+ import Utils .Order ;
19+
1720public class InsertionSort {
1821
1922
@@ -24,11 +27,11 @@ public class InsertionSort {
2427 * sorting byte type array
2528 *==========================*/
2629
27- public void sort (byte [] a ) {
30+ public static void sort (byte [] a ) {
2831 sort (a , a .length );
2932 }
3033
31- private void sort (byte [] a , int size ){
34+ private static void sort (byte [] a , int size ){
3235 byte target ;
3336 int j ;
3437
@@ -52,11 +55,11 @@ private void sort(byte[] a, int size ){
5255 * sorting char type array
5356 *==========================*/
5457
55- public void sort (char [] a ) {
58+ public static void sort (char [] a ) {
5659 sort (a , a .length );
5760 }
5861
59- private void sort (char [] a , int size ) {
62+ private static void sort (char [] a , int size ) {
6063
6164 char target ;
6265 int j ;
@@ -81,11 +84,11 @@ private void sort(char[] a, int size) {
8184 * sorting short type array
8285 *==========================*/
8386
84- public void sort (short [] a ) {
87+ public static void sort (short [] a ) {
8588 sort (a , a .length );
8689 }
8790
88- private void sort (short [] a , int size ) {
91+ private static void sort (short [] a , int size ) {
8992
9093 short target ;
9194 int j ;
@@ -110,11 +113,11 @@ private void sort(short[] a, int size) {
110113 * sorting int type array
111114 *==========================*/
112115
113- public void sort (int [] a ) {
116+ public static void sort (int [] a ) {
114117 sort (a , a .length );
115118 }
116119
117- private void sort (int [] a , int size ) {
120+ private static void sort (int [] a , int size ) {
118121
119122 int target , j ;
120123
@@ -138,11 +141,11 @@ private void sort(int[] a, int size) {
138141 * sorting long type array
139142 *==========================*/
140143
141- public void sort (long [] a ) {
144+ public static void sort (long [] a ) {
142145 sort (a , a .length );
143146 }
144147
145- private void sort (long [] a , int size ) {
148+ private static void sort (long [] a , int size ) {
146149
147150 long target ;
148151 int j ;
@@ -167,11 +170,11 @@ private void sort(long[] a, int size) {
167170 * sorting float type array
168171 *==========================*/
169172
170- public void sort (float [] a ) {
173+ public static void sort (float [] a ) {
171174 sort (a , a .length );
172175 }
173176
174- private void sort (float [] a , int size ) {
177+ private static void sort (float [] a , int size ) {
175178
176179 float target ;
177180 int j ;
@@ -196,11 +199,11 @@ private void sort(float[] a, int size) {
196199 * sorting double type array
197200 *==========================*/
198201
199- public void sort (double [] a ) {
202+ public static void sort (double [] a ) {
200203 sort (a , a .length );
201204 }
202205
203- private void sort (double [] a , int size ) {
206+ private static void sort (double [] a , int size ) {
204207
205208 double target ;
206209 int j ;
@@ -281,4 +284,99 @@ private static void sort(Object[] a, int size, Comparator c) {
281284 a [j + 1 ] = target ;
282285 }
283286 }
287+
288+
289+
290+ // reverse ordering
291+
292+ public static void sort (byte [] a , boolean isReverse ) {
293+
294+ // reverse order
295+ if (isReverse ) {
296+ Byte [] b = Convert .toByteArray (a );
297+ sort (b , Order .reverseOrder ());
298+ Convert .tobyteArray (b , a );
299+ }
300+ else {
301+ sort (a , a .length );
302+ }
303+ }
304+
305+ public static void sort (char [] a , boolean isReverse ) {
306+
307+ // reverse order
308+ if (isReverse ) {
309+ Character [] b = Convert .toCharacterArray (a );
310+ sort (b , Order .reverseOrder ());
311+ Convert .tocharArray (b , a );
312+ }
313+ else {
314+ sort (a , a .length );
315+ }
316+ }
317+
318+ public static void sort (short [] a , boolean isReverse ) {
319+
320+ // reverse order
321+ if (isReverse ) {
322+ Short [] b = Convert .toShortArray (a );
323+ sort (b , Order .reverseOrder ());
324+ Convert .toshortArray (b , a );
325+ }
326+ else {
327+ sort (a , a .length );
328+ }
329+ }
330+
331+ public static void sort (int [] a , boolean isReverse ) {
332+
333+ // reverse order
334+ if (isReverse ) {
335+ Integer [] b = Convert .toIntegerArray (a );
336+ sort (b , Order .reverseOrder ());
337+ Convert .tointtArray (b , a );
338+ }
339+ else {
340+ sort (a , a .length );
341+ }
342+ }
343+
344+ public static void sort (long [] a , boolean isReverse ) {
345+
346+ // reverse order
347+ if (isReverse ) {
348+ Long [] b = Convert .toLongArray (a );
349+ sort (b , Order .reverseOrder ());
350+ Convert .tolongArray (b , a );
351+ }
352+ else {
353+ sort (a , a .length );
354+ }
355+ }
356+
357+ public static void sort (float [] a , boolean isReverse ) {
358+
359+ // reverse order
360+ if (isReverse ) {
361+ Float [] b = Convert .toFloatArray (a );
362+ sort (b , Order .reverseOrder ());
363+ Convert .toflostArray (b , a );
364+ }
365+ else {
366+ sort (a , a .length );
367+ }
368+ }
369+
370+ public static void sort (double [] a , boolean isReverse ) {
371+
372+ // reverse order
373+ if (isReverse ) {
374+ Double [] b = Convert .toDoubleArray (a );
375+ sort (b , Order .reverseOrder ());
376+ Convert .todoubleArray (b , a );
377+ }
378+ else {
379+ sort (a , a .length );
380+ }
381+ }
284382}
0 commit comments